1- # -*- coding: utf-8 -*-
21#!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
34import json
45import os
56import random
67import requests
78import subprocess
89
910def get_cid ():
10- cid = "localfile"
1111 cid = input ("请输入CID(直接回车导入本地文件):" )
12- if cid == "localfile " :
12+ if cid == "" :
1313 file_path = input ("请输入文件绝对路径:" )
1414 while os .path .exists (file_path ) == False :
1515 print ("该路径文件不存在,请重新输入" )
1616 else :
1717 if os .path .isfile (file_path ):
18- ipfs_add_cmd = """ipfs add %s"""
18+ ipfs_add_cmd = """ipfs add %s""" % file_path
1919 ipfs_cli_output = str (subprocess .check_output (ipfs_add_cmd .split ()), "utf-8" )
2020 cid = ipfs_cli_output .split ()[- 2 ]
21- elif os .path .isfile (file_path ):
22- ipfs_add_cmd = """ipfs add -r %s"""
21+ elif os .path .isdir (file_path ):
22+ ipfs_add_cmd = """ipfs add -r %s""" % file_path
2323 ipfs_cli_output = str (subprocess .check_output (ipfs_add_cmd .split ()), "utf-8" )
2424 cid = ipfs_cli_output .split ()[- 2 ]
2525 else :
2626 pass
2727 else :
2828 pass
29+ print ("已获取到CID:%s" % cid )
2930 return cid
3031
3132def get_vshare_nodeid ():
@@ -48,7 +49,8 @@ def ipfs_gc(cid):
4849cid = get_cid ()
4950if mode == "1" :
5051 minerid = get_vshare_nodeid ()
51- subprocess .run ("expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid ), shell = True )
52+ cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid )
53+ subprocess .run (cmd , shell = True )
5254 print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
5355 if_gc = input ("是否清理刚刚导入的文件缓存?(y/n)" )
5456 if if_gc == "y" :
@@ -58,7 +60,8 @@ def ipfs_gc(cid):
5860 exit ()
5961elif mode == "2" :
6062 minerid = input ("请输入FileCoin节点ID(格式:f0xxxxx):" )
61- subprocess .run ("expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid ), shell = True )
63+ cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid , deal_duration , minerid )
64+ subprocess .run (cmd , shell = True )
6265 print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
6366 if_gc = input ("是否清理刚刚导入的文件缓存?(y/n)" )
6467 if if_gc == "y" :
@@ -69,7 +72,8 @@ def ipfs_gc(cid):
6972elif mode == "3" :
7073 deal_times = input ("请输入本次发起的交易次数(纯数字):" )
7174 max_budget = input ("请输入最大的价格预算(纯数字)" )
72- subprocess .run ("expect /opt/vsharecloud-tools/scripts/global_deal.sh %s %s %s %s" % (cid , deal_duration , max_budget , deal_times ), shell = True )
75+ cmd = "expect /opt/vsharecloud-tools/scripts/global_deal.sh %s %s %s %s" % (cid , deal_duration , max_budget , deal_times )
76+ subprocess .run (cmd , shell = True )
7377 print ("交易已发起,请通过命令 lotus client list-deals 查询交易状态" )
7478 if_gc = input ("是否清理刚刚导入的文件缓存?(y/n)" )
7579 if if_gc == "y" :
0 commit comments