@@ -108,24 +108,27 @@ def _assert_coll_exists(self):
108
108
'To create a new collection, run\n \n {1} init {0}' )
109
109
raise IOError (msg .format (self .coll_name , sys .argv [0 ]))
110
110
111
- def add_warcs (self , warcs , hardlink = False ):
111
+ def add_warcs (self , warcs , method = 'copy' ):
112
112
if not os .path .isdir (self .archive_dir ):
113
113
raise IOError ('Directory {0} does not exist' .
114
114
format (self .archive_dir ))
115
115
116
116
full_paths = []
117
117
for filename in warcs :
118
118
filename = os .path .abspath (filename )
119
- if hardlink :
119
+ logging .info ('%s %s to %s' ,
120
+ method ,
121
+ filename ,
122
+ self .archive_dir )
123
+ if method == 'hardlink' :
120
124
os .link (filename , os .path .join (self .archive_dir ,
121
125
os .path .basename (filename )))
126
+ elif method == 'symlink' :
127
+ os .symlink (filename , os .path .join (self .archive_dir ,
128
+ os .path .basename (filename )))
122
129
else :
123
130
shutil .copy2 (filename , self .archive_dir )
124
131
full_paths .append (os .path .join (self .archive_dir , filename ))
125
- logging .info ('%s %s to %s' ,
126
- hardlink and 'Linked' or 'Copied' ,
127
- filename ,
128
- self .archive_dir )
129
132
130
133
self ._index_merge_warcs (full_paths , self .DEF_INDEX_FILE )
131
134
@@ -364,13 +367,20 @@ def do_list(r):
364
367
# Add Warcs
365
368
def do_add (r ):
366
369
m = CollectionsManager (r .coll_name )
367
- m .add_warcs (r .files , r .hardlink )
370
+ m .add_warcs (r .files , r .method )
368
371
369
372
addwarc_help = 'Copy ARCS/WARCS to collection directory and reindex'
370
373
addwarc = subparsers .add_parser ('add' , help = addwarc_help )
371
374
addwarc .add_argument ('coll_name' )
372
375
addwarc .add_argument ('files' , nargs = '+' )
373
- addwarc .add_argument ('--hardlink' , '-l' , action = 'store_true' ,
376
+ addwarc .add_argument ('--method' , '-m' , default = 'copy' ,
377
+ help = 'import method (default: %(default)s)' ,
378
+ choices = ('copy' , 'symlink' , 'hardlink' ))
379
+ addwarc .add_argument ('--symlink' , '-s' , action = 'store_const' ,
380
+ dest = 'method' , const = 'symlink' ,
381
+ help = 'symlink files into storage instead of copying' )
382
+ addwarc .add_argument ('--hardlink' , '-l' , action = 'store_const' ,
383
+ dest = 'method' , const = 'hardlink' ,
374
384
help = 'hardlink files into storage instead of copying' )
375
385
addwarc .set_defaults (func = do_add )
376
386
0 commit comments