aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElisa Sohier <elisa.sohier@art-software.fr>2019-08-01 09:57:04 +0200
committerElisa Sohier <elisa.sohier@art-software.fr>2019-08-01 09:57:04 +0200
commitb454e3a4df00fc4ce60ec7a759fef1e6e849f85e (patch)
tree737cb10dd541c0b20023342e515c7b7be2be4a69
parent3b47005fa0e0267c061b3d5d244810b8b45fd639 (diff)
Fixed behaviour for default tabname
-rw-r--r--autosync/__init__.py59
1 files changed, 34 insertions, 25 deletions
diff --git a/autosync/__init__.py b/autosync/__init__.py
index 458a1f0..2a63928 100644
--- a/autosync/__init__.py
+++ b/autosync/__init__.py
@@ -60,7 +60,7 @@ def run():
global server
args = deque(sys.argv[1:])
if len(args) < 1:
- print("{0} @ – list available tab names\n{0} @@tabname – list available entries under tabname\n{0} @tabname entry1 entry2 – synchronizes entry1 and entry2 from tabname\n{0} @tabname – synchronizes every entry found in tabname\n{0} -s @[tabname][ entry1[ entry2[ …]]] – synchronizes in server mode (ie don't refresh timestamp)".format(os.path.basename(sys.argv[0])))
+ print("{0} @ – list available tab names\n{0} @@tabname – list available entries under tabname\n{0}[ @tabname] entry1 entry2 – synchronizes entry1 and entry2 from tabname (or default)\n{0} @tabname – synchronizes every entry found in tabname\n{0} -s [@tabname][ entry1[ entry2[ …]]] – synchronizes in server mode (ie don't refresh timestamp)\n\nIf tabname is omitted, will use default file located at ~/.autoSync.tab".format(os.path.basename(sys.argv[0])))
return
firstArg = args.popleft()
@@ -68,6 +68,8 @@ def run():
server = True
firstArg = args.popleft()
+ tabname = ""
+
if firstArg.startswith("@"):
if firstArg.startswith("@@"): # list available entries for tabfile
elts = list(getTab(name=firstArg.lstrip("@")))
@@ -76,37 +78,44 @@ def run():
maxLenSrc = max(len(line[1]) for line in elts)
maxLenDst = max(len(line[1]) for line in elts)
- msg("Available entries for tabfile {}:".format(firstArg.lstrip("@")))
+ msg("Available entries for tabfile {}:".format((lambda i: ["(default)", i][len(i)>0])(firstArg.lstrip("@"))))
print("\n\033[1;37m%-*s %-*s %-*s\033[0m" % (maxLenName, "Name", maxLenSrc, "Source", maxLenDst, "Target"))
for ename, esrc, edst in elts:
print("%-*s %-*s %-*s" % (maxLenName, ename, maxLenSrc, esrc, maxLenDst, edst))
+ return
elif firstArg == "@": # lists all available tabFiles
files = glob.glob(os.path.join(os.environ["HOME"], ".autoSync.*.tab"))
msg("Available tables:")
print("\n".join("– " + os.path.basename(fileName).split(".", 2)[2][:-4] for fileName in files))
+ return
else:
- firstArg = firstArg.lstrip("@")
- for name, src, dst in getTab(firstArg, args):
- srcT, dstT = getTimestamp(src, dst)
- ignoreFile = os.path.join(src, ".ignore.lst")
- if not os.path.exists(ignoreFile):
- ignoreFile = None
- if srcT >= dstT:
- msg("[{} @ {}] sending data to destination".format(name, firstArg))
- if not server:
- with open(os.path.join(src, ".lastsync"), "w") as f:
- f.write(str(time.time()))
- sync(src, dst, ignoreFile, True)
- else:
- msg("[{} @ {}] gathering data from destination".format(name, firstArg))
- sync(dst, src, ignoreFile, True)
- if not server:
- with open(os.path.join(src, ".lastsync"), "w") as f:
- f.write(str(time.time()))
-
- if os.path.exists("/tmp/source.ts"):
- os.unlink("/tmp/source.ts")
- if os.path.exists("/tmp/dest.ts"):
- os.unlink("/tmp/dest.ts")
+ tabname = firstArg.lstrip("@")
+ else:
+ args.appendleft(firstArg)
+
+ for name, src, dst in getTab(tabname, args):
+ srcT, dstT = getTimestamp(src, dst)
+ ignoreFile = os.path.join(src, ".ignore.lst")
+ if not os.path.exists(ignoreFile):
+ ignoreFile = None
+ if tabname == "":
+ tabname = "(default)"
+ if srcT >= dstT:
+ msg("[{} @ {}] sending data to destination".format(name, tabname))
+ if not server:
+ with open(os.path.join(src, ".lastsync"), "w") as f:
+ f.write(str(time.time()))
+ sync(src, dst, ignoreFile, True)
+ else:
+ msg("[{} @ {}] gathering data from destination".format(name, tabname))
+ sync(dst, src, ignoreFile, True)
+ if not server:
+ with open(os.path.join(src, ".lastsync"), "w") as f:
+ f.write(str(time.time()))
+
+ if os.path.exists("/tmp/source.ts"):
+ os.unlink("/tmp/source.ts")
+ if os.path.exists("/tmp/dest.ts"):
+ os.unlink("/tmp/dest.ts")