@@ -29,6 +29,11 @@ class Command(BaseCommand):
2929
3030 def add_arguments (self , parser ):
3131 parser .add_argument ('domain' )
32+ parser .add_argument (
33+ '--dir' ,
34+ dest = 'dir' ,
35+ help = "Optionally specify a directory to write the file to" ,
36+ )
3237 parser .add_argument ('--chunk-size' , type = int , default = 100 ,
3338 help = 'Maximum number of records to read from couch at once.' )
3439 parser .add_argument ('--limit-to-db' , dest = 'limit_to_db' ,
@@ -39,16 +44,23 @@ def add_arguments(self, parser):
3944
4045 @change_log_level ('boto3' , logging .WARNING )
4146 @change_log_level ('botocore' , logging .WARNING )
42- def handle (self , domain = None , reset = False ,
43- chunk_size = 100 , limit_to_db = None , ** options ):
47+ def handle (
48+ self ,
49+ domain = None ,
50+ dir = None ,
51+ reset = False ,
52+ chunk_size = 100 ,
53+ limit_to_db = None ,
54+ ** options ,
55+ ):
4456 already_exported = get_lines_from_file (options ['already_exported' ])
4557 print ("Found {} existing blobs, these will be skipped" .format (len (already_exported )))
4658
4759 if not domain :
4860 raise CommandError (USAGE )
4961
5062 self .stdout .write ("\n Running blob exporter\n {}" .format ('-' * 50 ))
51- export_filename = _get_export_filename (domain , already_exported )
63+ export_filename = _get_export_filename (domain , already_exported , path = dir )
5264 if os .path .exists (export_filename ):
5365 raise CommandError (
5466 f"Export file '{ export_filename } ' exists. Remove the file and re-run the command."
@@ -72,7 +84,10 @@ def get_lines_from_file(filename):
7284 return {line .strip () for line in f }
7385
7486
75- def _get_export_filename (domain , already_exported ):
87+ def _get_export_filename (domain , already_exported , path = None ):
7688 timestamp = datetime .datetime .now ().strftime ('%Y-%m-%d_%H.%M' )
7789 part = '-part' if already_exported else ''
78- return f'{ timestamp } -{ domain } -blobs{ part } .tar.gz'
90+ filename = f'{ timestamp } -{ domain } -blobs{ part } .tar.gz'
91+ if path :
92+ return os .path .join (path , filename )
93+ return filename
0 commit comments