# # # patch "monotone.py" # from [f631a13abcfbf989c417fbe2f7d3c5e9abc99d67] # to [17eb31b3ef7f75438d10aaa54f42a402d5083b52] # # patch "plain.py" # from [e99c23ed40ef207bf23cdd32888434957583826f] # to [1bb2b62c0e696d5e2ff6e79926734e0d34cbda64] # ============================================================ --- monotone.py f631a13abcfbf989c417fbe2f7d3c5e9abc99d67 +++ monotone.py 17eb31b3ef7f75438d10aaa54f42a402d5083b52 @@ -163,8 +163,8 @@ field += sep sep = pipe.read(1) yield field - - data = "" + + data = "" while 1: cmd, status, cont, size = get_fields() data += pipe.read(int(size)) @@ -251,3 +251,5 @@ return rv +def basic_io_parser(data): + return Monotone(None,None).basic_io_parser(data) ============================================================ --- plain.py e99c23ed40ef207bf23cdd32888434957583826f +++ plain.py 1bb2b62c0e696d5e2ff6e79926734e0d34cbda64 @@ -1,8 +1,11 @@ +# !/usr/bin/env python """ Simpler sync for monotone """ from optparse import OptionParser from dumb import Dumbtone +import os.path +import monotone import sys ACTIONS = [ "pull", "push", "sync"] @@ -14,6 +17,56 @@ sfp.set("default","hostKeys","~/.ssh/known_hosts") cfp.read(cfgfile) +def getTempDir(database): + try: + tmpDir = os.environ['TEMP'] + except KeyError: + try: + tmpDir = os.environ['TMP'] + except KeyError: + tmpDir = "/tmp" + if database[0].isalpha() and database[1] == ':': + database = "_" + database[0] + "_" + database[2:] + database = os.path.normpath(database) + return os.path.join(tmpDir, database + "-mtndumbtemp") + +def getDefaultDatabase(): + dir = "." + while True: + optionsFN = os.path.join(dir,"_MTN","options") + if os.path.exists(optionsFN): + fh = file(optionsFN,"r") + try: + for stanza in monotone.basic_io_parser(fh.read()): + for k,v in stanza: + if k == "database": + return v[0] + finally: + fh.close() + dir = os.path.join("..",dir) + if not os.path.exists(dir): break + return None + +def getDefaultUrl(): + try: + fh = file(".mtndumboptions","r") + try: + for stanza in monotone.basic_io_parser(fh.read()): + for k,v in stanza: + if k == "repository": + return v[0] + finally: + fh.close() + except IOError: + pass + return None + +def setDefaultUrl(url): + f = file(".mtndumboptions","w+") + print >> f, 'repository "%s"' % url + f.close() + return + def parseOpt(): par = OptionParser(usage= """%prog [options] pull|push|sync remote-URL @@ -48,14 +101,23 @@ elif args[0] not in ACTIONS: sys.exit("\nERROR: Invalid operation specified\n") elif len(args)==1: - sys.exit("\nERROR: Missing remote-URL\n") + defaultUrl = getDefaultUrl() + if defaultUrl is None: + sys.exit("\nERROR: Missing remote-URL\n") + args = [ args[0], defaultUrl ] else: sys.exit("\nERROR: Only one remote-URL allowed\n") if options.db is None: - sys.exit("\nERROR: monotone db not specified\n") - elif options.local is None: - sys.exit("\nERROR: local transit directory not specified\n") + options.db = getDefaultDatabase() + if options.db is None: + sys.exit("\nERROR: monotone db not specified and not in workspace\n") + if options.local is None: + import urlparse + defaultTmpDir = getTempDir(options.db) + if defaultTmpDir is None: + sys.exit("\nERROR: local transit directory not specified\n") + options.local = "file://" + defaultTmpDir return (options, args) if __name__ == "__main__": @@ -74,3 +136,5 @@ mtn.do_push(options.local, args[1], **optdict) elif args[0]=="sync": mtn.do_sync(options.local, args[1], **optdict) + + setDefaultUrl(args[1])