Эй блестящих умов там,Получение SyntaxError на последнюю строку коды в Unison Слияние сценарий
Я пытаюсь получить этот Python скрипт, который я нашел, работая и не могу понять, если это только у меня или если исходный плакат не получил код в порядке. Этот сценарий должен включить автоматическое разрешение конфликтов в Unison, используя команду merge
в файле prefs, взяв два конфликтующих файла и дублируя один из них с datestamp в имени файла. Оригинал posing is here, но не было никаких отступов, поэтому мне пришлось пройти и сделать это вручную, просто наблюдая за появляющимися ошибками. Ошибка, которую я не могу обойти сейчас
File "/bin/unison_merge.py", line 5, in <module>
PATH, CURRENT1, CURRENT2, NEW = sys.argv[1:]
ValueError: need more than 0 values to unpack
Я надеюсь, что кто-то там будет в состоянии помочь мне.
Я включил весь сценарий ниже в надежде, что это поможет и что будут обнаружены любые другие ошибки :).
#!/usr/bin/env python2.7
import sys, os, datetime, os, filecmp
PATH, CURRENT1, CURRENT2, NEW = sys.argv[1:]
# see http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#merge
promote_remote = False
backup_file_color = "red"
def is_suffix(a, b): return b[-len(a):] == a
def merge(PATH, CURRENT1, CURRENT2, NEW, promote_remote):
# CURRENT1 is copy of local, CURRENT2 is copy of remote
if filecmp.cmp(CURRENT1, CURRENT2, shallow = False):
# special case -- files have same contents
# not a real conflict. just use local copy, no backup
print "merge of identical files"
os.link(CURRENT1, NEW)
return
# PATH is relative to unison root.
# We need to know absolute path.
# We get it, assuming CURRENT1 is an absolute path
# referring to a file in the same subdirectory as PATH.
assert CURRENT1[0] == '/', "CURRENT1 (%s) is not absolute path" % CURRENT1
PATH_dir, PATH_tail = os.path.split(PATH)
ABS_dir = os.path.dirname(CURRENT1)
assert is_suffix(PATH_dir, ABS_dir), "%s not suffix of %s!" % (PATH_dir, ABS_dir)
ABS_PATH = os.path.join(ABS_dir, PATH_tail)
timestamp = datetime.datetime.now().strftime("%y%m%d_%H%M")
(root, ext) = os.path.splitext(PATH_tail)
for counter in range(100):
counter = " %d" % counter if counter else ""
filename = "%s @%s%s%s" % (root, timestamp, counter, ext)
BACKUP = os.path.join(ABS_dir, filename)
if not os.path.exists(BACKUP): break
else:
assert False, "too many existing backups %s" % BACKUP
# promote_remote = False
# seems to retain file props, saving update in next sync?
print "CONFLICT:", ABS_PATH
if promote_remote:
# resolve conflict by using remote copy, while backing up local to
BACKUP
CURRENT1, CURRENT2 = CURRENT2, CURRENT1
print "CONFLICT remote saved as", filename
else:
print "CONFLICT local saved as", filename
assert os.path.isfile(CURRENT1)
assert not os.path.exists(NEW)
assert not os.path.exists(BACKUP)
os.link(CURRENT1, BACKUP)
os.link(CURRENT2, NEW)
if backup_file_color and backup_file_color != 'none':
mac_color_file(BACKUP, backup_file_color)
# note: coloring the tmp file NEW is useless - not propagated
# coloring the current file ABS_PATH causes UNISON to complain
# chmod -w BACKUP
# os.chmod(BACKUP, stat.S_IRUSR)
# just for coloring file in mac Finder
def mac_color_file(file, color):
if not os.path.exists("/usr/bin/osascript"): return
color_map = {
"none":0,
"orange":1,
"red":2,
"yellow":3,
"blue":4,
"purple":5,
"green":6,
"gray":7,
}
assert color in color_map
assert file[0] == '/', 'absolute path required'
assert os.path.exists(file)
#see http://stackoverflow.com/questions/2435580/tagging-files-with-colors-in-os-x-finder-from-shell-scripts
#osascript -e "tell application \"Finder\" to set label index of alias POSIX
file ("$filename\" to $label")
cmd = '''/usr/bin/osascript -e 'tell application "Finder" to set label index of alias POSIX file "%s" to %d' > /dev/null ''' % (file, color_map[color])
try:
retcode = subprocess.call(cmd, shell=True)
if retcode < 0:
print >>sys.stderr, "mac_color_file child was terminated by signal", retcode
elif retcode > 0:
print >>sys.stderr, "mac_color_file child returned", retcode
except OSError, e:
print >>sys.stderr, "mac_color_file child failed:", e
### main ###
merge(PATH, CURRENT1, CURRENT2, NEW, promote_remote)
Упс, слева, что выплюнул. Но теперь ошибка, которую я вижу, это Файл «/bin/unison_merge.py», строка 5, в PATH, CURRENT1, CURRENT2, NEW = sys.argv [1:] ValueError: требуется больше 0 значений для распаковки –
smithjw
@smithjw: программе нужны 4 ввода в командной строке, которые распаковываются в указанные переменные. – pyfunc