-
Notifications
You must be signed in to change notification settings - Fork 0
/
xnat_sync
executable file
·750 lines (719 loc) · 26.5 KB
/
xnat_sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
#!/usr/bin/python
# Copyright (c) 2011 Christian Haselgrove
# BSD License: http://www.opensource.org/licenses/bsd-license.php
import sys
import os
import time
import datetime
import getpass
import dateutil.parser
import pyxnat
def command_line_error(msg):
sys.stderr.write('%s: %s\n' % (progname, msg))
sys.stderr.write('run %s with no arguments for usage\n' % progname)
return
def write_rc(xnat_uri, resource_uri, files):
fo = open('.xnat', 'w')
fo.write('%s\n' % xnat_uri)
fo.write('%s\n' % resource_uri)
fo.write('%s\n' % datetime.datetime.now().strftime('%s'))
for path in sorted(files):
times = files[path]
fo.write('%d %d %s\n' % (times['t_local'], times['t_remote'], path))
fo.close()
return
def read_rc():
fo = open('.xnat')
xnat_uri = fo.readline().strip()
resource_uri = fo.readline().strip()
last_updated = int(fo.readline().strip())
files = {}
for line in fo:
(t_local, t_remote, path) = line.strip('\n').split(' ', 2)
files[path] = {'t_remote': int(t_remote), 't_local': int(t_local)}
fo.close()
return (xnat_uri, resource_uri, last_updated, files)
def get_statuses(rc_files, resource):
all_files = set(rc_files)
remote_files = {}
for f in resource.files():
path = f.attributes()['path']
t_remote = int(dateutil.parser.parse(f.last_modified()).strftime('%s'))
remote_files[path] = t_remote
all_files.add(path)
local_files = {}
for (dirpath, dirnames, filenames) in os.walk('.'):
for filename in filenames:
path = '%s/%s' % (dirpath, filename)
# remote initial './'
path = path[2:]
if path == '.xnat':
continue
local_files[path] = int(os.stat(path).st_mtime)
all_files.add(path)
statuses = {}
for path in sorted(all_files):
if path not in rc_files:
if path in local_files:
local_code = 'N'
else:
local_code = '-'
elif path not in local_files:
local_code = 'D'
elif local_files[path] == rc_files[path]['t_local']:
local_code = 'U'
elif local_files[path] > rc_files[path]['t_local']:
local_code = 'M'
else:
local_code = '?'
if path not in rc_files:
if path in remote_files:
remote_code = 'N'
else:
remote_code = '-'
elif path not in remote_files:
remote_code = 'D'
elif remote_files[path] == rc_files[path]['t_remote']:
remote_code = 'U'
elif remote_files[path] > rc_files[path]['t_remote']:
remote_code = 'M'
else:
remote_code = '?'
statuses[path] = {'local': local_code, 'remote': remote_code}
return statuses
def files_times(path, f):
t_local = int(os.stat(path).st_mtime)
t_remote = int(dateutil.parser.parse(f.last_modified()).strftime('%s'))
return {'t_remote': t_remote, 't_local': t_local}
def connect(uri, user, password):
if user is None:
return pyxnat.Interface(uri, anonymous=True)
return pyxnat.Interface(uri, user, password)
def display_project_resources(project):
print '+ Project %s' % project.id()
display_resources(project.resources(), ' ')
for subject in project.subjects():
display_subject_resources(subject, ' ')
return
def display_subject_resources(subject, prefix=''):
print '%s+ Subject %s' % (prefix, subject.label())
display_resources(subject.resources(), prefix)
for experiment in subject.experiments():
display_experiment_resources(experiment, prefix + ' ')
return
def display_experiment_resources(experiment, prefix=''):
print '%s+ Experiment %s' % (prefix, experiment.label())
display_resources(experiment.resources(), prefix)
for scan in experiment.scans():
display_scan_resources(scan, prefix + ' ')
for reconstruction in experiment.reconstructions():
print '%s + Reconstruction %s' % (prefix, reconstruction.label())
display_resources(reconstruction.in_resources(), prefix + ' ', 'In')
display_resources(reconstruction.out_resources(), prefix + ' ', 'Out')
for assessor in experiment.assessors():
print '%s + Assessment %s' % (prefix, assessor.label())
display_resources(assessor.in_resources(), prefix + ' ', 'In')
display_resources(assessor.out_resources(), prefix + ' ', 'Out')
return
def display_scan_resources(scan, prefix=''):
print '%s+ Scan %s' % (prefix, scan.id())
display_resources(scan.resources(), prefix + ' ')
return
def display_resources(cobject, prefix, res_pre=None):
resources = [ r for r in cobject ]
resources.sort(lambda a, b: cmp(int(a.id()), int(b.id())))
for r in resources:
n_files = len([ f for f in r.files() ])
if not res_pre:
print '%s * Resource %5s: %s (%d files)' % (prefix, r.id(), r.label(), n_files)
else:
print '%s * %s Resource %5s: %s (%d files)' % (prefix, res_pre, r.id(), r.label(), n_files)
def get_object(i, argv):
"""return a pyxnat object given given command line:
project [subject [experiment]]
prints a message and returns None on error
"""
if not sys.argv:
command_line_error('no project given')
return None
project_id = sys.argv.pop(0)
project = i.select.project(project_id)
if not project.exists():
sys.stderr.write("%s: can't find project %s\n" % (progname, project_id))
return None
if not sys.argv:
return project
subject_id = sys.argv.pop(0)
subject = project.subject(subject_id)
if not subject.exists():
sys.stderr.write("%s: can't find subject %s for project %s\n" % (progname, subject_id, project_id))
return None
if not sys.argv:
return subject
experiment_id = sys.argv.pop(0)
experiment = subject.experiment(experiment_id)
if not experiment.exists():
sys.stderr.write("%s: can't find experiment %s for subject %s\n" % (progname, experiment_id, subject_id))
return None
if not sys.argv:
return experiment
scan_name = sys.argv.pop(0)
scan = experiment.scan(scan_name)
if not scan.exists():
sys.stderr.write("%s: can't find scan %s for experiment %s\n" % (progname, scan_name, experiment_id))
return None
return scan
def find_resources(object, resource_id):
resources = []
if object._urt == 'projects':
for subject in object.subjects():
resources.extend(find_resources(subject, resource_id))
elif object._urt == 'subjects':
for experiment in object.experiments():
resources.extend(find_resources(experiment, resource_id))
elif object._urt == 'experiments':
for scan in object.scans():
resources.extend(find_resources(scan, resource_id))
for assessor in object.assessors():
for r in assessor.in_resources():
if r.id() == resource_id or r.label() == resource_id:
resources.append(r)
for r in assessor.out_resources():
if r.id() == resource_id or r.label() == resource_id:
resources.append(r)
for recon in object.reconstructions():
for r in recon.in_resources():
if r.id() == resource_id or r.label() == resource_id:
resources.append(r)
for r in recon.out_resources():
if r.id() == resource_id or r.label() == resource_id:
resources.append(r)
elif object._urt == 'scans':
for r in object.resources():
if r.id() == resource_id or r.label() == resource_id:
resources.append(r)
else:
for r in object.resources():
if r.id() == resource_id or r.label() == resource_id:
resources.append(r)
return resources
def display_parents(object, prefix=''):
prefix = prefix + ' '
parent = object.parent()
type = parent._urt[:-1]
print '%sfor %s %s' % (prefix, type, parent.label())
if type != 'project':
display_parents(parent, prefix)
return
def get_file(f, path):
"get a file, but first make directories"
dirs = []
dir = os.path.dirname(path)
while dir:
dirs.append(dir)
dir = os.path.dirname(dir)
dirs.reverse()
for dir in dirs:
if not os.path.exists(dir):
os.mkdir(dir)
f.get(path)
return
progname = os.path.basename(sys.argv.pop(0))
try:
env_user = os.environ['XNAT_USER']
except KeyError:
env_user = None
try:
env_password = os.environ['XNAT_PASSWORD']
except KeyError:
env_password = None
dry_run_flag = False
unauth_flag = False
cl_user = None
cl_password = None
lag = 5
if not sys.argv:
print
print 'usage: %s [options] command [command arguments ...]' % progname
print
print 'options are:'
print
print ' -d -- dry run (no actual changes)'
print ' -u <user name> -- XNAT user name'
print ' -p <password> -- XNAT password'
print ' -n -- use unauthenticated connection'
print ' -l <time in seconds> -- lag after writing before checking XNAT '
print ' modification time (default %d)' % lag
print
print 'option values may be given by environment variables:'
print
if env_user is None:
print ' user name: XNAT_USER (not set)'
else:
print ' user name: XNAT_USER (set to %s)' % env_user
if env_password is None:
print ' password: XNAT_PASSWORD (not set)'
else:
print ' password: XNAT_PASSWORD (currently set)'
print
print 'if none are given, %s will prompt for them' % progname
print
print 'commands and arguments are:'
print
print ' list <XNAT URI> <project> [subject [experiment [scan]]] -- list resources'
print ' init -c <XNAT URI> <resource URI> -- create and associate with a resource'
print ' init <XNAT URI> <resource URI> -- associate with a resource'
print ' init <XNAT URI> <project> [subject [experiment [scan]]] <resource ID>'
print ' -- associate with a resource'
print ' status -- print file-by-file synchronization status'
print ' info -- print information about the association'
print ' push [-f] -- (force) push changes to the server'
print ' pull [-f] -- (force) pull changes from the server'
print
print 'status lines are:'
print
print ' local_status remote_status path'
print
print 'status codes are:'
print
print ' N -- new'
print ' U -- unchanged'
print ' M -- modified'
print ' D -- deleted'
print ' ? -- modification time is before last sync'
print ' - -- does not exist (only occurs if the counterpart has status N)'
print
print 'push/pull updates are performed as follows (source/dest/action):'
print
print ' N N update if forced'
print ' N - update'
print ' U MD? update if forced'
print ' M U update'
print ' M MD? update if forced'
print ' D UD update'
print ' D M? update if forced'
print ' ? UMD update if forced'
print ' - N update if forced'
print
sys.exit(1)
"""
DEST
N U M D ? -
N f x x x x u
S U x f f f x
R M x u f f f x
C D x u f u f x
? x f f f f x
- f x x x x x
"""
while sys.argv:
if not sys.argv[0] or sys.argv[0][0] != '-':
break
if sys.argv[0] == '-d':
dry_run_flag = True
sys.argv.pop(0)
continue
if sys.argv[0] == '-n':
unauth_flag = True
sys.argv.pop(0)
continue
if sys.argv[0] == '-u':
sys.argv.pop(0)
if not sys.argv:
command_line_error('-u requires an argument')
sys.exit(1)
cl_user = sys.argv.pop(0)
continue
if sys.argv[0] == '-p':
sys.argv.pop(0)
if not sys.argv:
command_line_error('-p requires an argument')
sys.exit(1)
cl_password = sys.argv.pop(0)
continue
if sys.argv[0] == '-l':
sys.argv.pop(0)
if not sys.argv:
command_line_error('-l requires an argument')
sys.exit(1)
s_lag = sys.argv.pop(0)
try:
lag = int(lag)
except ValueError:
command_line_error('bad lag value "%s"' % s_lag)
sys.exit(1)
command_line_error('unknown option "%s"' % sys.argv[0])
sys.exit(1)
if not sys.argv:
command_line_error('no command given')
sys.exit(1)
if unauth_flag:
print 'using unauthenticated connection'
user = None
password = None
else:
if cl_user is not None:
user = cl_user
elif env_user is not None:
user = env_user
else:
sys.stdout.write('User name: ')
sys.stdout.flush()
user = sys.stdin.readline().strip()
if cl_password is not None:
password = cl_password
elif env_password is not None:
password = env_password
else:
password = getpass.getpass()
if not sys.argv:
command_line_error('no command given')
sys.exit(1)
command = sys.argv.pop(0)
if command == 'list':
if not sys.argv:
command_line_error('no URI given')
sys.exit(1)
xnat_uri = sys.argv.pop(0)
i = connect(xnat_uri, user, password)
object = get_object(i, sys.argv)
if object is None:
sys.exit(1)
if object._urt == 'projects':
display_project_resources(object)
elif object._urt == 'subjects':
display_subject_resources(object)
elif object._urt == 'experiments':
display_experiment_resources(object)
else:
display_scan_resources(object)
elif command == 'init':
if os.path.exists('.xnat'):
sys.stderr.write('%s: .xnat exists, already a sync dir\n' % progname)
sys.exit(1)
if sys.argv[0] == '-c':
sys.argv.pop(0)
try:
xnat_uri = sys.argv.pop(0)
resource_uri = sys.argv.pop(0)
except IndexError:
command_line_error('not enough arguments to init')
sys.exit(1)
i = connect(xnat_uri, user, password)
resource = i.select(resource_uri)
if resource.exists():
sys.stderr.write('%s: resource exists\n' % progname)
sys.exit(1)
if dry_run_flag:
print 'not creating resource'
else:
print 'creating resource'
resource.create()
else:
xnat_uri = sys.argv.pop(0)
i = connect(xnat_uri, user, password)
if len(sys.argv) == 1:
resource_uri = i.select(resource_uri)
if not resource.exists():
sys.stderr.write("%s: can't find resource\n" % progname)
sys.exit(1)
else:
resource_id = sys.argv.pop()
object = get_object(i, sys.argv)
print 'searching for resource...'
resources = find_resources(object, resource_id)
if not resources:
sys.stderr.write('%s: resource %s not found\n' % (progname, resource_id))
sys.exit(1)
if len(resources) > 1:
sys.stderr.write('%s: multiple resources %s found\n' % (progname, resource_id))
sys.exit(1)
resource = resources[0]
files = {}
if dry_run_flag:
print 'not writing .xnat'
else:
print 'writing .xnat'
write_rc(xnat_uri, resource._uri, files)
elif command == 'status':
(xnat_uri, resource_uri, last_updated, rc_files) = read_rc()
i = connect(xnat_uri, user, password)
resource = i.select(resource_uri)
if not resource.exists():
sys.stderr.write("%s: can't find resource\n" % progname)
sys.exit(1)
statuses = get_statuses(rc_files, resource)
for path in sorted(statuses):
print '%s %s %s' % (statuses[path]['local'],
statuses[path]['remote'],
path)
elif command == 'info':
(xnat_uri, resource_uri, last_updated, rc_files) = read_rc()
i = connect(xnat_uri, user, password)
resource = i.select(resource_uri)
if not resource.exists():
sys.stderr.write("%s: can't find resource\n" % progname)
sys.exit(1)
print 'Host: %s' % xnat_uri
print 'Resource URI: %s' % resource_uri
dt = datetime.datetime.fromtimestamp(last_updated)
print 'Last synchronized: %s' % dt.strftime('%a %b %d %H:%M:%S %Y')
print 'Resource: %s (%s)' % (resource.label(), resource.id())
display_parents(resource)
elif command == 'push':
if sys.argv and sys.argv[0] == '-f':
force_flag = True
else:
force_flag = False
(xnat_uri, resource_uri, last_updated, rc_files) = read_rc()
i = connect(xnat_uri, user, password)
resource = i.select(resource_uri)
if not resource.exists():
sys.stderr.write("%s: can't find resource\n" % progname)
sys.exit(1)
statuses = get_statuses(rc_files, resource)
updates = []
for path in sorted(statuses):
if statuses[path]['local'] == 'N':
if statuses[path]['remote'] == 'N':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.put(path)
updates.append((path, f))
if statuses[path]['remote'] == '-':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.put(path)
updates.append((path, f))
if statuses[path]['local'] == 'D':
if statuses[path]['remote'] == 'D':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
del rc_files[path]
if statuses[path]['remote'] == 'M':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.delete()
del rc_files[path]
if statuses[path]['remote'] == 'U':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.delete()
del rc_files[path]
if statuses[path]['local'] == 'M':
if statuses[path]['remote'] == 'D':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.put(path)
updates.append((path, f))
if statuses[path]['remote'] == 'M':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.put(path)
updates.append((path, f))
if statuses[path]['remote'] == 'U':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.put(path)
updates.append((path, f))
if statuses[path]['local'] == 'U':
if statuses[path]['remote'] == 'D':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.put(path)
updates.append((path, f))
if statuses[path]['remote'] == 'M':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
f.put(path)
updates.append((path, f))
if not updates:
print 'nothing updated'
elif dry_run_flag:
print 'not updating .xnat'
else:
print 'waiting %d seconds...' % lag
for i in xrange(lag):
sys.stdout.write('%d...' % (lag-i))
sys.stdout.flush()
time.sleep(1)
print '0'
for (path, f) in updates:
print 'getting times for %s' % path
rc_files[path] = files_times(path, f)
write_rc(xnat_uri, resource_uri, rc_files)
elif command == 'pull':
if sys.argv and sys.argv[0] == '-f':
force_flag = True
else:
force_flag = False
(xnat_uri, resource_uri, last_updated, rc_files) = read_rc()
i = connect(xnat_uri, user, password)
resource = i.select(resource_uri)
if not resource.exists():
sys.stderr.write("%s: can't find resource\n" % progname)
sys.exit(1)
statuses = get_statuses(rc_files, resource)
prunes = []
for path in sorted(statuses):
if statuses[path]['local'] == '?' or statuses[path]['remote'] == '?':
print 'panic: %s' % path
prunes.append(path)
elif statuses[path]['local'] == 'N' and statuses[path]['remote'] != '-':
print 'panic: %s' % path
prunes.append(path)
elif statuses[path]['remote'] == 'N' and statuses[path]['local'] != '-':
print 'panic: %s' % path
prunes.append(path)
elif statuses[path]['local'] == '-' and statuses[path]['remote'] != 'N':
print 'panic: %s' % path
prunes.append(path)
elif statuses[path]['remote'] == '-' and statuses[path]['local'] != 'N':
print 'panic: %s' % path
prunes.append(path)
for path in prunes:
del statuses[path]
for path in sorted(statuses):
if statuses[path]['remote'] == 'N':
if statuses[path]['local'] == 'N':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
get_file(f, path)
rc_files[path] = files_times(path, f)
if statuses[path]['local'] == '-':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
get_file(f, path)
rc_files[path] = files_times(path, f)
if statuses[path]['remote'] == 'D':
if statuses[path]['local'] == 'D':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
del rc_files[path]
if statuses[path]['local'] == 'M':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
os.unlink(path)
del rc_files[path]
if statuses[path]['local'] == 'U':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
os.unlink(path)
del rc_files[path]
if statuses[path]['remote'] == 'M':
if statuses[path]['local'] == 'D':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
get_file(f, path)
rc_files[path] = files_times(path, f)
if statuses[path]['local'] == 'M':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
get_file(f, path)
rc_files[path] = files_times(path, f)
if statuses[path]['local'] == 'U':
if dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
get_file(f, path)
rc_files[path] = files_times(path, f)
if statuses[path]['remote'] == 'U':
if statuses[path]['local'] == 'D':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
get_file(f, path)
rc_files[path] = files_times(path, f)
if statuses[path]['local'] == 'M':
if not force_flag:
print 'conflict: %s' % path
elif dry_run_flag:
print 'not updating %s' % path
else:
print 'updating %s' % path
f = resource.file(path)
get_file(f, path)
rc_files[path] = files_times(path, f)
if dry_run_flag:
print 'not writing .xnat'
else:
print 'writing .xnat'
write_rc(xnat_uri, resource_uri, rc_files)
else:
command_line_error('unknown command "%s"' % command)
sys.exit(1)
sys.exit(0)
# eof