1515from kubo_datatypes import PinType
1616from kubo_rpc_api import KuboRPC
1717from filebase_pin_api import FilebasePinAPI
18+ from logger import setup_logger
1819
19- RPC = KuboRPC (log_filepath = "logs/backup_filebase_locally.log" ,
20+ LOG_LOCATION : str = 'logs/backup_filebase_locally.log'
21+ RPC = KuboRPC (log_filepath = LOG_LOCATION ,
2022 log_level = logging .DEBUG )
21- FILEBASE_API = FilebasePinAPI (log_filepath = "logs/backup_filebase_locally.log" ,
23+ FILEBASE_API = FilebasePinAPI (log_filepath = LOG_LOCATION ,
2224 log_level = logging .DEBUG )
25+ logger : logging .Logger = setup_logger (LOG_LOCATION , level = logging .DEBUG )
2326BUCKETS : List [str ] = [
2427 'kleros' ,
2528 'kleros-v2' ,
@@ -87,12 +90,13 @@ def get_missing_cids(local_filepath: str, filebase_filepath: str) -> set[str]:
8790 """
8891 local_cids : List [str ] = get_local_node_pins (filepath = local_filepath )
8992 filebase_cids : List [str ] = get_filebase_pins (filepath = filebase_filepath )
90- print (
93+ logger . info (
9194 f"The local pinset has { len (local_cids )} cids, we have found { len (filebase_cids )} in filebase." )
9295 missing_cids : set [str ] = set (filebase_cids ) - set (local_cids )
9396 filebase_missing_cids = set (local_cids ) - set (filebase_cids )
94- print (f"There are { len (missing_cids )} missing CIDs in the local node" )
95- print (
97+ logger .info (
98+ f"There are { len (missing_cids )} missing CIDs in the local node" )
99+ logger .info (
96100 f"Filebase is missing { len (filebase_missing_cids )} CIDs." )
97101 if len (filebase_missing_cids ) > 0 :
98102 print (f"Missing CIDs in filebase: { filebase_missing_cids } " )
@@ -103,33 +107,33 @@ def get_missing_cids(local_filepath: str, filebase_filepath: str) -> set[str]:
103107 local_node_pin_filepath : str = './local_node_pins.json'
104108 filebase_pins_filepath : str = './filebase_pins.json'
105109
106- print ("Updating local node pin ls" )
110+ logger . info ("Updating local node pin ls" )
107111 # recursive pins is enough to get all the pins
108112 RPC .pin_ls (filepath = local_node_pin_filepath ,
109113 pin_type = PinType .RECURSIVE )
110114
111115 # update Filebase pinset
112- print ("Updating Filebase pin ls" )
116+ logger . info ("Updating Filebase pin ls" )
113117 for bucket in BUCKETS :
114118 # there is no need to get the output, we are going to read from the
115119 # filepath stored in the filepath
116120 FILEBASE_API .get_all_cids (
117121 bucket_name = bucket , filepath = filebase_pins_filepath )
118122
119- print ("Checking Missing CIDs" )
123+ logger . info ("Checking Missing CIDs" )
120124 missed_cids : set [str ] = get_missing_cids (local_filepath = local_node_pin_filepath ,
121125 filebase_filepath = filebase_pins_filepath )
122126
123127 # Add missed CIDs into local IPFS node
124128 n_missed_cids = len (missed_cids )
125129 for index , missed_cid in enumerate (missed_cids ):
126- print (f"Progress: { index / n_missed_cids * 100 :.2f} %" )
130+ logger . info (f"Progress: { index / n_missed_cids * 100 :.2f} %" )
127131 try :
128132 RPC .pin_add (cid = missed_cid , timeout = 2 )
129- print (f"{ missed_cid } added to local ipfs node" )
133+ logger . info (f"{ missed_cid } added to local ipfs node" )
130134 except ReadTimeout :
131- print ("Error while trying to pin, timeout error, most probably we don't have as peer filebase nodes. " ,
132- f"CID { missed_cid } will be skipped" )
135+ logger . info ("Error while trying to pin, timeout error, most probably we don't have as peer filebase nodes. " ,
136+ f"CID { missed_cid } will be skipped" )
133137 except Exception as e :
134- print (f"Unknown exception for cid { missed_cid } " )
135- print (e )
138+ logger . info (f"Unknown exception for cid { missed_cid } " )
139+ logger . info (e )
0 commit comments