aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-10-27 15:00:27 +0000
committerng0 <ng0@n0.is>2019-10-27 15:00:27 +0000
commitfe70b5d608ebb438cf2ec56ae030c9ece9d483cf (patch)
tree15b9cfe8e1c173bc7eac2dab84ee736cbad8cc3e
parent83eb77dafd5054bee67dc9cc05dca8dc23ecd7f0 (diff)
downloadgnunet-dev/ng0/python-modularized.tar.gz
gnunet-dev/ng0/python-modularized.zip
initial, not yet working gnunet_pytools.dev/ng0/python-modularized
-rw-r--r--contrib/scripts/.gitignore1
-rw-r--r--contrib/scripts/Makefile.am4
-rw-r--r--contrib/scripts/gnunet_pytools.py.in78
3 files changed, 82 insertions, 1 deletions
diff --git a/contrib/scripts/.gitignore b/contrib/scripts/.gitignore
index 547c89185..b1ddb9699 100644
--- a/contrib/scripts/.gitignore
+++ b/contrib/scripts/.gitignore
@@ -1,2 +1,3 @@
1gnunet-chk.py 1gnunet-chk.py
2removetrailingwhitespace.py 2removetrailingwhitespace.py
3gnunet_pytools.py
diff --git a/contrib/scripts/Makefile.am b/contrib/scripts/Makefile.am
index 5dc94439b..525031761 100644
--- a/contrib/scripts/Makefile.am
+++ b/contrib/scripts/Makefile.am
@@ -9,7 +9,8 @@ noinst_SCRIPTS = \
9 removetrailingwhitespace.py \ 9 removetrailingwhitespace.py \
10 gnunet_pyexpect.py \ 10 gnunet_pyexpect.py \
11 gnunet_janitor.py \ 11 gnunet_janitor.py \
12 gnunet-chk.py 12 gnunet-chk.py \
13 gnunet_pytools.py
13 14
14bin_SCRIPTS = \ 15bin_SCRIPTS = \
15 gnunet-bugreport 16 gnunet-bugreport
@@ -20,6 +21,7 @@ EXTRA_DIST = \
20 gnunet_pyexpect.py.in \ 21 gnunet_pyexpect.py.in \
21 gnunet_janitor.py.in \ 22 gnunet_janitor.py.in \
22 gnunet-chk.py.in \ 23 gnunet-chk.py.in \
24 gnunet_pytools.py.in \
23 $(SCRIPTS) \ 25 $(SCRIPTS) \
24 removetrailingwhitespace.py.in \ 26 removetrailingwhitespace.py.in \
25 pydiffer.py.in 27 pydiffer.py.in
diff --git a/contrib/scripts/gnunet_pytools.py.in b/contrib/scripts/gnunet_pytools.py.in
new file mode 100644
index 000000000..cc02d1330
--- /dev/null
+++ b/contrib/scripts/gnunet_pytools.py.in
@@ -0,0 +1,78 @@
1#!@PYTHON@
2# This file is part of GNUnet
3# (C) 2019 GNUnet e.V.
4#
5# Authors:
6# Author: ng0 <ng0@taler.net>
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted.
10#
11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
14# LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
15# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
17# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
18# THIS SOFTWARE.
19#
20# SPDX-License-Identifier: 0BSD
21
22import os
23from distutils.spawn import find_executable
24
25
26def existence(name):
27 return find_executable(name) is not None
28
29
30# GNUNET_TMP which we suggest to use in place of the absolute definition of
31# /tmp. So instead of /tmp/foo you would write $GNUNET_TMP/foo. The usage
32# of $GNUNET_TMP/foo, will result in $TMPDIR/gnunet/foo, or $TMP/gnunet/foo
33# and finally, if TMPDIR is undefined, /tmp/gnunet/foo.
34# 'TEMP' is not (yet) covered by GNUNET_TMP.
35# TODO: merge these two functions?
36def gnunet_tmp_path():
37 if os.environ.get('GNUNET_TMP'):
38 return os.environ.get('GNUNET_TMP')
39 elif os.environ.get('TMPDIR'):
40 return os.environ.get('TMPDIR') + '/gnunet'
41 elif os.environ.get('TMP'):
42 return os.environ.get('TMP') + '/gnunet'
43 elif os.environ.get('TEMP'):
44 return os.environ.get('TEMP') + '/gnunet'
45 else:
46 return '/tmp/gnunet'
47
48
49def tmp_path():
50 if os.environ.get('TMPDIR'):
51 return os.environ.get('TMPDIR')
52 elif os.environ.get('TMP'):
53 return os.environ.get('TMP')
54 elif os.environ.get('TEMP'):
55 return os.environ.get('TEMP')
56 else:
57 return '/tmp'
58
59
60def get_path(name):
61 dpath = {
62 'exec_prefix': '@exec_prefix@',
63 'libexecdir': '@libexecdir@',
64 'gnunet_prefix': os.environ.get('GNUNET_PREFIX', None),
65 'tmp': tmp_path(),
66 'gnunet_tmp': gnunet_tmp_path()
67 }
68 try:
69 return dpath[name]
70 except KeyError:
71 return []
72
73
74def suffix_executable(name):
75 if os.name == 'posix':
76 return string(name)
77 if os.name == 'nt':
78 return string(name + '.exe')