diff options
Diffstat (limited to 'contrib/scripts/gnunet_pytools.py.in')
-rw-r--r-- | contrib/scripts/gnunet_pytools.py.in | 78 |
1 files changed, 78 insertions, 0 deletions
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 | |||
22 | import os | ||
23 | from distutils.spawn import find_executable | ||
24 | |||
25 | |||
26 | def 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? | ||
36 | def 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 | |||
49 | def 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 | |||
60 | def 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 | |||
74 | def suffix_executable(name): | ||
75 | if os.name == 'posix': | ||
76 | return string(name) | ||
77 | if os.name == 'nt': | ||
78 | return string(name + '.exe') | ||