Ticket #597: 597-tahoesync-stub.diff

File 597-tahoesync-stub.diff, 2.9 KB (added by warner, at 2009-01-29T20:07:19Z)

starting point, just a stub of the CLI command

  • src/allmydata/scripts/cli.py

    diff -rN -u old-597-sync/src/allmydata/scripts/cli.py new-597-sync/src/allmydata/scripts/cli.py
    old new  
    188188    def getSynopsis(self):
    189189        return "%s ln FROM TO" % (os.path.basename(sys.argv[0]),)
    190190
     191class SyncOptions(VDriveOptions):
     192    def parseArgs(self, localdir, topath):
     193        self.from_dir = localdir
     194        self.to_dir = topath
     195
     196    def getSynopsis(Self):
     197        return "%s sync FROM ALIAS:TO" % os.path.basename(sys.argv[0])
     198
     199    longdesc = """Make a (tahoe) target directory look exactly like a (local) directory. Behaves like 'rsync -a --delete'."""
     200
    191201class WebopenOptions(VDriveOptions):
    192202    def parseArgs(self, where=''):
    193203        self.where = where
     
    264274    ["rm", None, RmOptions, "Unlink a file or directory in the virtual drive."],
    265275    ["mv", None, MvOptions, "Move a file within the virtual drive."],
    266276    ["ln", None, LnOptions, "Make an additional link to an existing file."],
     277    ["sync", None, SyncOptions, "Make target dir look like local dir."],
    267278    ["webopen", None, WebopenOptions, "Open a webbrowser to the root_dir"],
    268279    ["manifest", None, ManifestOptions, "List all files/dirs in a subtree"],
    269280    ["stats", None, StatsOptions, "Print statistics about all files/dirs in a subtree"],
     
    335346    rc = tahoe_mv.mv(options, mode="link")
    336347    return rc
    337348
     349def sync(options):
     350    from allmydata.scripts import tahoe_sync
     351    rc = tahoe_sync.sync(options)
     352    return rc
     353
    338354def webopen(options, opener=None):
    339355    from allmydata.scripts import tahoe_webopen
    340356    rc = tahoe_webopen.webopen(options, opener=opener)
     
    372388    "rm": rm,
    373389    "mv": mv,
    374390    "ln": ln,
     391    "sync": sync,
    375392    "webopen": webopen,
    376393    "manifest": manifest,
    377394    "stats": stats,
  • src/allmydata/scripts/tahoe_sync.py

    diff -rN -u old-597-sync/src/allmydata/scripts/tahoe_sync.py new-597-sync/src/allmydata/scripts/tahoe_sync.py
    old new  
     1
     2import os.path
     3import urllib
     4import simplejson
     5from allmydata.scripts.common import get_alias, escape_path, DefaultAliasMarker
     6from allmydata.scripts.common_http import do_http
     7from allmydata import uri
     8
     9def sync(options):
     10    nodeurl = options['node-url']
     11    from_dir = options.from_dir
     12    to_dir = options.to_dir
     13    if options['quiet']:
     14        verbosity = 0
     15    else:
     16        verbosity = 2
     17    stdin = options.stdin
     18    stdout = options.stdout
     19    stderr = options.stderr
     20
     21    if nodeurl[-1] != "/":
     22        nodeurl += "/"
     23    rootcap, path = get_alias(options.aliases, options.to_dir, DEFAULT_ALIAS)
     24    url = nodeurl + "uri/%s/" % urllib.quote(rootcap)
     25    if path:
     26        url += escape_path(path)
     27