@@ -21,7 +21,7 @@ def check_database_connection(user, password):
2121 conn = psycopg2 .connect (
2222 database = GLOBAL_CONFIG .get ("DATABASE" , "database_name" ),
2323 user = user ,
24- password = password
24+ password = password ,
2525 )
2626 conn .close ()
2727 return True
@@ -48,28 +48,28 @@ def update_app_config(web_app_path):
4848
4949 # Update the apiServer value
5050 api_server = GLOBAL_CONFIG .get ("WEB_APP" , "api_server" )
51- config [' apiServer' ] = api_server
51+ config [" apiServer" ] = api_server
5252
5353 # Update PhiloLogic paths to point to the restored data
5454 source_data_path = web_app_path / "source_data"
5555 if source_data_path .exists ():
56- config [' sourcePhiloDBPath' ] = str (source_data_path .absolute ())
56+ config [" sourcePhiloDBPath" ] = str (source_data_path .absolute ())
5757
5858 target_data_path = web_app_path / "target_data"
5959 if target_data_path .exists ():
60- config [' targetPhiloDBPath' ] = str (target_data_path .absolute ())
61- elif ' targetPhiloDBPath' in config :
60+ config [" targetPhiloDBPath" ] = str (target_data_path .absolute ())
61+ elif " targetPhiloDBPath" in config :
6262 # If target_data doesn't exist and there was a target path, remove it
63- config [' targetPhiloDBPath' ] = ""
63+ config [" targetPhiloDBPath" ] = ""
6464
6565 # Write the updated config back
66- with open (config_path , 'w' ) as f :
66+ with open (config_path , "w" ) as f :
6767 json .dump (config , f , indent = 2 )
6868
6969 print (f"Updated appConfig.json:" )
7070 print (f" - apiServer: { api_server } " )
7171 print (f" - sourcePhiloDBPath: { config ['sourcePhiloDBPath' ]} " )
72- if config .get (' targetPhiloDBPath' ):
72+ if config .get (" targetPhiloDBPath" ):
7373 print (f" - targetPhiloDBPath: { config ['targetPhiloDBPath' ]} " )
7474
7575 return True
@@ -91,11 +91,11 @@ def run_npm_build(web_app_path):
9191
9292 # Run npm install
9393 print ("Running npm install..." )
94- subprocess .run ([' npm' , ' install' ], check = True )
94+ subprocess .run ([" npm" , " install" ], check = True )
9595
9696 # Run npm build
9797 print ("Running npm run build..." )
98- subprocess .run ([' npm' , ' run' , ' build' ], check = True )
98+ subprocess .run ([" npm" , " run" , " build" ], check = True )
9999
100100 return True
101101
@@ -117,12 +117,12 @@ def check_existing_resources(db_name, db_user, db_password, web_app_dest, backup
117117 # Check for existing tables
118118 sql_files = list (backup_dir .glob ("textpair_*.sql" ))
119119 for sql_file in sql_files :
120- table_name = sql_file .stem .replace (' textpair_' , '' )
120+ table_name = sql_file .stem .replace (" textpair_" , "" )
121121 with psycopg2 .connect (database = db_name , user = db_user , password = db_password ) as conn :
122122 with conn .cursor () as cursor :
123123 cursor .execute (
124124 "SELECT 1 FROM information_schema.tables WHERE table_name = %s" ,
125- (table_name ,)
125+ (table_name ,),
126126 )
127127 if cursor .fetchone () is not None :
128128 existing_resources .append (f"database table '{ table_name } '" )
@@ -176,12 +176,12 @@ def restore_textpair_database(backup_path, web_app_dest=None, force=False):
176176 # Extract the tarball using lz4 module
177177 print ("\n Extracting backup archive..." )
178178 print (" - Decompressing with LZ4..." )
179- with open (backup_path , 'rb' ) as f :
179+ with open (backup_path , "rb" ) as f :
180180 compressed_data = f .read ()
181181 decompressed_data = lz4 .frame .decompress (compressed_data )
182182 print (" - Extracting files..." )
183183 temp_tar = temp_dir / "temp.tar"
184- with open (temp_tar , 'wb' ) as f :
184+ with open (temp_tar , "wb" ) as f :
185185 f .write (decompressed_data )
186186 os .system (f"tar xf { temp_tar } -C { temp_dir } " )
187187 os .remove (temp_tar )
@@ -209,8 +209,10 @@ def restore_textpair_database(backup_path, web_app_dest=None, force=False):
209209 print ("\n WARNING: The following resources will be overwritten:" )
210210 for resource in existing :
211211 print (f" - { resource } " )
212- response = input ("\n Do you want to proceed with the restoration? This will replace all existing resources (y/n): " )
213- if response .lower () != 'y' :
212+ response = input (
213+ "\n Do you want to proceed with the restoration? This will replace all existing resources (y/n): "
214+ )
215+ if response .lower () != "y" :
214216 print ("Restoration cancelled" )
215217 return
216218 print ("" ) # Empty line for better readability
@@ -224,7 +226,7 @@ def restore_textpair_database(backup_path, web_app_dest=None, force=False):
224226 print (f"Found { len (sql_files )} tables to restore" )
225227
226228 for sql_file in sql_files :
227- table_name = sql_file .stem .replace (' textpair_' , '' )
229+ table_name = sql_file .stem .replace (" textpair_" , "" )
228230
229231 # Drop existing table if it exists
230232 print (f" - Processing { table_name } :" )
@@ -236,7 +238,7 @@ def restore_textpair_database(backup_path, web_app_dest=None, force=False):
236238
237239 # Restore table
238240 print (f" • Restoring table data..." )
239- os .system (f' PGPASSWORD={ db_password } psql -U { db_user } -d { db_name } -f { sql_file } ' )
241+ os .system (f" PGPASSWORD={ db_password } psql -U { db_user } -d { db_name } -f { sql_file } " )
240242 print (f" ✓ Table { table_name } restored" )
241243
242244 print ("✓ Database restoration complete" )
@@ -290,10 +292,17 @@ def restore_textpair_database(backup_path, web_app_dest=None, force=False):
290292if __name__ == "__main__" :
291293 parser = ArgumentParser ()
292294 parser .add_argument ("backup_path" , type = str , help = "Path to the backup tarball file" )
293- parser .add_argument ("--web_app_dest" , type = str , default = "" ,
294- help = "Optional destination path for web app files" )
295- parser .add_argument ("--force" , action = "store_true" ,
296- help = "Overwrite existing files/tables without prompting" )
295+ parser .add_argument (
296+ "--web_app_dest" ,
297+ type = str ,
298+ default = "" ,
299+ help = "Optional destination path for web app files" ,
300+ )
301+ parser .add_argument (
302+ "--force" ,
303+ action = "store_true" ,
304+ help = "Overwrite existing files/tables without prompting" ,
305+ )
297306 args = parser .parse_args ()
298307
299- restore_textpair_database (args .backup_path , args .web_app_dest , args .force )
308+ restore_textpair_database (args .backup_path , args .web_app_dest , args .force )
0 commit comments