扫描文件:sol文件版本号

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/usr/bin/python
# -*- coding: utf-8 -*-
# solc.py

def scan(fileName):
    # 打开文件
    f = open(fileName, 'r')
    # 读取文件
    lines = f.readlines()
    for line in lines:
        if ("pragma" in line):
            index = line.find(".")
            return line[index + 1]
    f.close()

if __name__ == '__main__':
  scan() 

批量编译文件到指定目录

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
suffix="sol"
dir=$(eval pwd)

for file in $(ls $dir | grep .${suffix})
do
	checkresult=`python -c "import solc; print solc.scan('$file')"`
	echo $checkresult
	# 切换solc版本
	if [ $checkresult -eq 4 ]
    	then
       		solc-select use 0.4.26
		echo "change solc version 0.4.26"
    	fi
	if [ $checkresult -eq 5 ]
    	then
       		solc-select use 0.5.17
		echo "change solc version 0.5.17"
    	fi
	if [ $checkresult -eq 6 ]
    	then
       		solc-select use 0.6.12
		echo "change solc version 0.6.12"
    	fi
	if [ $checkresult -eq 7 ]
    	then
       		solc-select use 0.7.6
		echo "change solc version 0.7.6"
    	fi
	if [ $checkresult -eq 8 ]
    	then
       		solc-select use 0.8.16
		echo "change solc version 0.8.16"
    	fi
	# 执行solc 编译
	# solc --bin -o `outputDirPath` ${file}
	# solc --bin -o `outputDirPath` `./*.sol`
done
echo "ok"

批量修改文件名后缀

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/bin/bash
oldsuffix="bin"
newsuffix="hex"
dir=$(eval pwd)

for file in $(ls $dir | grep .${oldsuffix})
do
        name=$(ls ${file} | cut -d. -f1)
        mv $file ${name}.${newsuffix}
done
echo "ok"

批量测试文件(位于/vandal/tools目录下)

1
bulk_analyser/analyse.py -d ../examples ../datalog/demo_analyse.dl