461
from cPickle import dump, load
466
from weavefile import write_weave_v1, read_weave_v1
464
w = load(file(argv[2], 'rb'))
469
w = read_weave_v1(file(argv[2], 'rb'))
465
470
# at the moment, based on everything in the file
466
471
parents = set(range(len(w._v)))
467
ver = w.add(parents, sys.stdin.readlines())
468
dump(w, file(argv[2], 'wb'))
472
lines = [x.rstrip('\n') for x in sys.stdin.xreadlines()]
473
ver = w.add(parents, lines)
474
write_weave_v1(w, file(argv[2], 'wb'))
469
475
print 'added %d' % ver
470
476
elif cmd == 'init':
472
478
if os.path.exists(fn):
473
479
raise IOError("file exists")
475
dump(w, file(fn, 'wb'))
481
write_weave_v1(w, file(fn, 'wb'))
476
482
elif cmd == 'get':
477
w = load(file(argv[2], 'rb'))
483
w = read_weave_v1(file(argv[2], 'rb'))
478
484
sys.stdout.writelines(w.get(int(argv[3])))
479
485
elif cmd == 'annotate':
480
w = load(file(argv[2], 'rb'))
486
w = read_weave_v1(file(argv[2], 'rb'))
481
487
# assumes lines are ended
483
489
for origin, text in w.annotate(int(argv[3])):
490
assert '\n' not in text
486
491
if origin == lasto:
487
492
print ' | %s' % (text)