]> arthur.barton.de Git - bup.git/commitdiff
server: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Fri, 12 Feb 2021 20:28:01 +0000 (14:28 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:39 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/server.py
lib/cmd/bup

index b237aafbe51e9b8b3f78aebb9328ad26c507a523..3ff8a19164a7207c4c88fbf6f33b6692738fba10 100755 (executable)
@@ -1,29 +1,9 @@
-#!/bin/sh
-"""": # -*-python-*-
-# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
-export "BUP_ARGV_0"="$0"
-arg_i=1
-for arg in "$@"; do
-    export "BUP_ARGV_${arg_i}"="$arg"
-    shift
-    arg_i=$((arg_i + 1))
-done
-# Here to end of preamble replaced during install
-bup_python="$(dirname "$0")/../../../config/bin/python" || exit $?
-exec "$bup_python" "$0"
-"""
-# end of bup preamble
 
 from __future__ import absolute_import
-
-# Intentionally replace the dirname "$0" that python prepends
-import os, sys
-sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..'
-
 from binascii import hexlify, unhexlify
-import struct, subprocess
+import os, struct, subprocess, sys
 
-from bup import compat, options, git, vfs, vint
+from bup import options, git, vfs, vint
 from bup.compat import environ, hexstr
 from bup.git import MissingObject
 from bup.helpers import (Conn, debug1, debug2, linereader, lines_until_sentinel,
@@ -36,6 +16,7 @@ suspended_w = None
 dumb_server_mode = False
 repo = None
 
+
 def do_help(conn, junk):
     conn.write(b'Commands:\n    %s\n' % b'\n    '.join(sorted(commands)))
     conn.ok()
@@ -278,13 +259,6 @@ def resolve(conn, args):
 optspec = """
 bup server
 """
-o = options.Options(optspec)
-(opt, flags, extra) = o.parse(compat.argv[1:])
-
-if extra:
-    o.fatal('no arguments expected')
-
-debug2('bup server: reading from stdin.\n')
 
 commands = {
     b'quit': None,
@@ -304,26 +278,35 @@ commands = {
     b'resolve': resolve
 }
 
-# FIXME: this protocol is totally lame and not at all future-proof.
-# (Especially since we abort completely as soon as *anything* bad happens)
-sys.stdout.flush()
-conn = Conn(byte_stream(sys.stdin), byte_stream(sys.stdout))
-lr = linereader(conn)
-for _line in lr:
-    line = _line.strip()
-    if not line:
-        continue
-    debug1('bup server: command: %r\n' % line)
-    words = line.split(b' ', 1)
-    cmd = words[0]
-    rest = len(words)>1 and words[1] or b''
-    if cmd == b'quit':
-        break
-    else:
-        cmd = commands.get(cmd)
-        if cmd:
-            cmd(conn, rest)
+def main(argv):
+    o = options.Options(optspec)
+    opt, flags, extra = o.parse_bytes(argv[1:])
+
+    if extra:
+        o.fatal('no arguments expected')
+
+    debug2('bup server: reading from stdin.\n')
+
+    # FIXME: this protocol is totally lame and not at all future-proof.
+    # (Especially since we abort completely as soon as *anything* bad happens)
+    sys.stdout.flush()
+    conn = Conn(byte_stream(sys.stdin), byte_stream(sys.stdout))
+    lr = linereader(conn)
+    for _line in lr:
+        line = _line.strip()
+        if not line:
+            continue
+        debug1('bup server: command: %r\n' % line)
+        words = line.split(b' ', 1)
+        cmd = words[0]
+        rest = len(words)>1 and words[1] or b''
+        if cmd == b'quit':
+            break
         else:
-            raise Exception('unknown server command: %r\n' % line)
+            cmd = commands.get(cmd)
+            if cmd:
+                cmd(conn, rest)
+            else:
+                raise Exception('unknown server command: %r\n' % line)
 
-debug1('bup server: done\n')
+    debug1('bup server: done\n')
index 2f1570fc0231501d853b611fd888415846328daf..caf52492b5a2b39f186c25dcc1d3c822b5b08ff0 100755 (executable)
@@ -207,6 +207,7 @@ try:
                            b'prune-older',
                            b'random',
                            b'rm',
+                           b'server',
                            b'split',
                            b'tag',
                            b'tick',