File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/python3
2+
3+ from os .path import *
4+ import argparse
5+ import os
6+ import shutil
7+
8+
9+ def main ():
10+ parser = argparse .ArgumentParser ()
11+ parser .add_argument ("-s" , "--sandbox" )
12+ parser .add_argument ("-v" , "--verbose" , action = "store_true" )
13+ parser .add_argument ("-l" , "--link" , action = "store_true" )
14+ parser .add_argument ("-e" , "--export" , action = "store_true" )
15+ parser .add_argument ("files" , nargs = "*" )
16+ args = parser .parse_args ()
17+
18+ assert args .sandbox , "You must specify a sandbox directory"
19+ assert args .link ^ args .export , "You can't link and export at the same time"
20+
21+ if args .link :
22+ os .makedirs (args .sandbox , exist_ok = True )
23+ for f in args .files :
24+ sf = join (args .sandbox , f )
25+ if args .verbose :
26+ print ("link" , sf )
27+ os .makedirs (dirname (sf ), exist_ok = True )
28+ try :
29+ os .link (abspath (f ), sf )
30+ except PermissionError :
31+ shutil .copy (f , sf )
32+
33+ if args .export :
34+ for f in args .files :
35+ sf = join (args .sandbox , f )
36+ if args .verbose :
37+ print ("export" , sf )
38+ df = dirname (f )
39+ if df :
40+ os .makedirs (df , exist_ok = True )
41+ os .rename (sf , f )
42+
43+
44+ main ()
You can’t perform that action at this time.
0 commit comments