Ronny Pfannschmidt avatar Ronny Pfannschmidt committed a2e3e39

move some command implementations to the new utils module

Comments (0)

Files changed (2)

 import py
 import json
 
+
+from bmst.backup_app import make_backup
+from bmst.managed import BMST, check_bmst, dumb_sync
+from bmst.store import FileStore, Httplib2Store
+from bmst.utils import archive, extract, sync, get_bmst
+
 parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
 parser.convert_arg_line_to_args = shlex.split
 
 parser.add_argument('target', default=None, nargs='?')
 
 
-from bmst.backup_app import make_backup
-from bmst.managed import BMST, check_bmst, dumb_sync
-from bmst.store import FileStore, Httplib2Store
-
-
 def main():
     opts = parser.parse_args()
     if opts.debug:
         from bmst.wsgi import app
         app.bmst = bmst
         app.run()
-
-
-def get_bmst(path):
-    if path.startswith('http'):
-        path = path.rstrip('/')
-        blobs = Httplib2Store(path + '/blobs/')
-        meta = Httplib2Store(path + '/meta/')
-    else:
-        root = py.path.local(path)
-        root.ensure(dir=1)
-        meta = FileStore(root.ensure('meta', dir=1))
-        blobs = FileStore(root.ensure('blobs', dir=1))
-    return BMST(meta=meta, blobs=blobs)
-
-
-def sync(target, sources):
-    for source in sources:
-        print('pulling from', source)
-        other = get_bmst(source)
-        dumb_sync(source=other.meta, target=target.meta)
-        dumb_sync(source=other.blobs, target=target.blobs)
-
-
-def extract(bmst, key, target):
-    print('extracting to', target)
-    target = py.path.local(target)
-    meta = bmst.load_meta(key=key)
-    for name, key in meta['items'].items():
-        data = bmst.load_blob(key=key)
-        target.ensure(name).write(data)
-
-
-def archive(bmst, key, target):
-    """
-    create the archive `target` from the iems of the metadata stored at `key`
-    """
-    from mercurial import archival
-    kind = archival.guesskind(target)
-    if kind is None:
-        print('unknown archive type for', target)
-    archiver = archival.archivers[kind]
-    #XXX should it use the project + data s prefix?
-    prefix = archival.tidyprefix(target, kind, '')
-
-    def write(name, data):
-        archiver.addfile('%s/%s' % (prefix, name), 0755, False, data)
-
-    meta = bmst.load_meta(key=key)
-    print('archiving to', target)
-    archiver = archiver(target, meta['timestamp'])
-    write('.bmst', json.dumps(meta, indent=2, sort_keys=1))
-    for name, key in meta['items'].items():
-        data = bmst.load_blob(key=key)
-        write(name, data)
-
-    archiver.done()
+from __future__ import print_function
+import json
+import py
+from bmst.managed import dumb_sync, BMST
+from bmst.store import FileStore, Httplib2Store
+
+
+def get_bmst(path):
+    if path.startswith('http'):
+        path = path.rstrip('/')
+        blobs = Httplib2Store(path + '/blobs/')
+        meta = Httplib2Store(path + '/meta/')
+    else:
+        root = py.path.local(path)
+        root.ensure(dir=1)
+        meta = FileStore(root.ensure('meta', dir=1))
+        blobs = FileStore(root.ensure('blobs', dir=1))
+    return BMST(meta=meta, blobs=blobs)
+
+
+def sync(target, sources):
+    for source in sources:
+        print('pulling from', source)
+        other = get_bmst(source)
+        dumb_sync(source=other.meta, target=target.meta)
+        dumb_sync(source=other.blobs, target=target.blobs)
+
+
+def extract(bmst, key, target):
+    print('extracting to', target)
+    target = py.path.local(target)
+    meta = bmst.load_meta(key=key)
+    for name, key in meta['items'].items():
+        data = bmst.load_blob(key=key)
+        target.ensure(name).write(data)
+
+
+def archive(bmst, key, target):
+    """
+    create the archive `target` from the iems of the metadata stored at `key`
+    """
+    from mercurial import archival
+    kind = archival.guesskind(target)
+    if kind is None:
+        print('unknown archive type for', target)
+        return
+    archiver = archival.archivers[kind]
+    #XXX should it use the project + data s prefix?
+    prefix = archival.tidyprefix(target, kind, '')
+
+    def write(name, data):
+        archiver.addfile('%s/%s' % (prefix, name), 0755, False, data)
+
+    meta = bmst.load_meta(key=key)
+    print('archiving to', target)
+    archiver = archiver(target, meta['timestamp'])
+    write('.bmst', json.dumps(meta, indent=2, sort_keys=1))
+    for name, key in meta['items'].items():
+        data = bmst.load_blob(key=key)
+        write(name, data)
+
+    archiver.done()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.