Repository navigation
Expand file tree
/
Copy pathcompile.py
More file actions
executable file
·83 lines (66 loc) · 2.54 KB
/
Copy pathcompile.py
File metadata and controls
executable file
·83 lines (66 loc) · 2.54 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
import os
import logging
from pathlib import Path
from boa3.boa3 import Boa3
from boa3.builtin.type import UInt160
from boa3.neo.cryptography import hash160
from contextlib import contextmanager
import sys, os
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout
def cleanup(cleaned=False):
if not cleaned:
if os.path.exists(CONTRACT_PATH_NEF):
os.remove(CONTRACT_PATH_NEF)
if os.path.exists(CONTRACT_PATH_NEFDBG):
os.remove(CONTRACT_PATH_NEFDBG)
if os.path.exists(CONTRACT_PATH_JSON):
os.remove(CONTRACT_PATH_JSON)
else:
if os.path.exists(CONTRACT_PATH_PY_CLEANED):
os.remove(CONTRACT_PATH_PY_CLEANED)
def preprocess_contract(to_remove, path, path_cleaned, base_path):
with open(path) as oldfile, open(path_cleaned, 'w') as newfile:
debug_block = False
for line in oldfile:
if any(dbg_block in line for dbg_block in list(debug_block_start)):
print("found start")
debug_block = True
if any(dbg_block in line for dbg_block in list(debug_block_end)):
print("found end")
debug_block = False
continue
if debug_block:
continue
if not any(to_remove in line for to_remove in to_remove):
newfile.write(line)
os.rename(path, base_path + "/temp.py")
os.rename(path_cleaned, path)
def build_contract(path):
Boa3.compile_and_save(path)
GHOST_ROOT = str(os.getcwd())
to_remove = ['debug(']
debug_block_start = ['#DEBUG_START']
debug_block_end = ['#DEBUG_END']
CONTRACT_DIR = GHOST_ROOT + '/contracts/NEP11/'
CONTRACT_PATH_PY = GHOST_ROOT + '/contracts/NEP11/Diamond.NFT.py'
CONTRACT_PATH_PY2 = GHOST_ROOT + '/contracts/NEP11/Diamond2.NFT.py'
CONTRACT_PATH_JSON = GHOST_ROOT + '/contracts/NEP11/Diamond.NFT.manifest.json'
CONTRACT_PATH_NEFDBG = GHOST_ROOT + '/contracts/NEP11/Diamond.NFT.nefdbgnfo'
CONTRACT_PATH_NEF = GHOST_ROOT + '/contracts/NEP11/Diamond.NFT.nef'
CONTRACT_PATH_PY_CLEANED = GHOST_ROOT + '/contracts/NEP11/Diamond.NFT_cleaned.py'
cleanup()
preprocess_contract(to_remove, CONTRACT_PATH_PY, CONTRACT_PATH_PY_CLEANED, CONTRACT_DIR)
with suppress_stdout():
build_contract(CONTRACT_PATH_PY)
os.rename(CONTRACT_DIR + "/temp.py", CONTRACT_PATH_PY2)
os.remove(CONTRACT_PATH_PY2)
cleanup(True)