]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/compat.py
Convert top level executables to binaries and clean up clean
[bup.git] / lib / bup / compat.py
index 2cd6fbaf8a3cbb01074b325ec55be62119ac7880..a06ffe8ee581d9cab13e1764740241768d2d2210 100644 (file)
@@ -169,41 +169,27 @@ else:  # Python 2
 
     buffer = buffer
 
-
-argv = None
-argvb = None
-
-def _configure_argv():
-    global argv, argvb
-    assert not argv
-    assert not argvb
-    if len(sys.argv) > 1:
-        if environ.get(b'BUP_ARGV_0'):
-            print('error: BUP_ARGV* set and sys.argv not empty', file=sys.stderr)
-            sys.exit(2)
-        argv = sys.argv
-        argvb = [argv_bytes(x) for x in argv]
-        return
-    args = []
-    i = 0
-    arg = environ.get(b'BUP_ARGV_%d' % i)
-    while arg is not None:
-        args.append(arg)
-        i += 1
-        arg = environ.get(b'BUP_ARGV_%d' % i)
-    i -= 1
-    while i >= 0:
-        del environ[b'BUP_ARGV_%d' % i]
-        i -= 1
-    argvb = args
-    # System encoding?
+try:
+    import bup_main
+except ModuleNotFoundError:
+    bup_main = None
+
+if bup_main:
+    def get_argvb():
+        "Return a new list containing the current process argv bytes."
+        return bup_main.argv()
     if py3:
-        argv = [x.decode(errors='surrogateescape') for x in args]
+        def get_argv():
+            "Return a new list containing the current process argv strings."
+            return [x.decode(errors='surrogateescape') for x in bup_main.argv()]
     else:
-        argv = argvb
-
-_configure_argv()
-
+        def get_argv():
+            return bup_main.argv()
+else:
+    def get_argvb():
+        raise Exception('get_argvb requires the bup_main module');
+    def get_argv():
+        raise Exception('get_argv requires the bup_main module');
 
 def wrap_main(main):
     """Run main() and raise a SystemExit with the return value if it