33import json
44import os
55import sys
6+ import time
67import shutil
78import random
89import requests
@@ -16,7 +17,7 @@ def get_config(config_path):
1617 else :
1718 print ("Config文件不存在!请检查文件路径或使用其他模式" )
1819 exit ()
19- return config ["mode" ],config ["file_path" ],config ["deal_duration" ],config ["if_gc" ],config ["minerid" ],config ["deal_times" ],config ["max_budget" ],config ["config_path" ],config ["encrypt_mode" ],config ["encrypt_key" ]
20+ return config ["mode" ],config ["file_path" ],config ["deal_duration" ],config ["if_gc" ],config ["minerid" ],config ["deal_times" ],config ["max_budget" ],config ["config_path" ],config ["encrypt_mode" ],config ["encrypt_key" ], config [ "cid_saving_path" ]
2021
2122def get_opt ():
2223 #在这里设定参数默认值
@@ -30,6 +31,7 @@ def get_opt():
3031 config_path = None
3132 encrypt_mode = None
3233 encrypt_key = "VshareCloud"
34+ cid_saving_path = None
3335 #===============#
3436 args = sys .argv
3537 del args [0 ]
@@ -57,12 +59,14 @@ def get_opt():
5759 encrypt_mode = str (opt_content )
5860 elif opt_name in ("--encryptkey" ,"-k" ):
5961 encrypt_key = str (opt_content )
62+ elif opt_name in ("--cid_saving_path" ,"-o" ):
63+ cid_saving_path = str (opt_content )
6064 else :
6165 pass
6266 if config_path != None :
6367 return get_config (config_path )
6468 else :
65- return mode ,file_path ,deal_duration ,if_gc ,minerid ,deal_times ,max_budget ,config_path ,encrypt_mode ,encrypt_key
69+ return mode ,file_path ,deal_duration ,if_gc ,minerid ,deal_times ,max_budget ,config_path ,encrypt_mode ,encrypt_key , cid_saving_path
6670
6771
6872def get_cid (file_path ,encrypt_mode ,encrypt_key ):
@@ -130,6 +134,15 @@ def get_vshare_nodeid():
130134 print ("已选取到节点:%s" % minerid )
131135 return minerid
132136
137+ def backup_cid (cid ,cid_saving_path ):
138+ if cid_saving_path != None :
139+ f = open ("%s/vshare_cids.md" % cid_saving_path ,'a' )
140+ f .write (str (cid )+ "|" + str (int (time .time ())))
141+ f .write ('\n ' )
142+ else :
143+ pass
144+ pass
145+
133146def ipfs_gc (cid ):
134147 print ("开始垃圾清理" )
135148 subprocess .run ("ipfs pin rm %s" % cid , shell = True )
@@ -148,11 +161,13 @@ def ipfs_gc(cid):
148161config_path = opt [7 ]
149162# encrypt_mode = opt[8]
150163# encrypt_key = opt[9]
164+ cid_saving_path = opt [10 ]
151165if mode == "1" :
152166 minerid = get_vshare_nodeid ()
153167 cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid )
154168 subprocess .run (cmd , shell = True )
155169 print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
170+ backup_cid (cid ,cid_saving_path )
156171 if if_gc == "y" :
157172 ipfs_gc (cid )
158173 else :
@@ -162,6 +177,7 @@ def ipfs_gc(cid):
162177 cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid )
163178 subprocess .run (cmd , shell = True )
164179 print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
180+ backup_cid (cid ,cid_saving_path )
165181 if if_gc == "y" :
166182 ipfs_gc (cid )
167183 else :
@@ -171,6 +187,7 @@ def ipfs_gc(cid):
171187 cmd = "expect /opt/vsharecloud-tools/scripts/global_deal.sh %s %s %s %s" % (cid , deal_duration , max_budget , deal_times )
172188 subprocess .run (cmd , shell = True )
173189 print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
190+ backup_cid (cid ,cid_saving_path )
174191 if if_gc == "y" :
175192 ipfs_gc (cid )
176193 else :
0 commit comments