minor tweaking
parent
653dd4d5b6
commit
a882cdca9e
72
run.py
72
run.py
|
@ -4,7 +4,6 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
import binascii
|
|
||||||
|
|
||||||
|
|
||||||
class Sins():
|
class Sins():
|
||||||
|
@ -18,32 +17,28 @@ class Sins():
|
||||||
if os.path.isdir(run_dir):
|
if os.path.isdir(run_dir):
|
||||||
self.run_dir = os.path.abspath(run_dir)
|
self.run_dir = os.path.abspath(run_dir)
|
||||||
|
|
||||||
path = self.scrap_recent(self.run_dir)
|
self.seed = os.path.abspath(seed)
|
||||||
if not path:
|
|
||||||
path = os.path.abspath(seed)
|
|
||||||
|
|
||||||
self.seed = path
|
|
||||||
|
|
||||||
parent = os.path.abspath(parent)
|
parent = os.path.abspath(parent)
|
||||||
if not os.path.isfile(parent):
|
if not os.path.isfile(parent):
|
||||||
raise ValueError('Invalid executable image path.')
|
raise ValueError('Invalid executable image path.')
|
||||||
|
|
||||||
self.parent = os.path.abspath(parent)
|
self.parent = parent
|
||||||
|
|
||||||
parsed = self.parent, self.seed, self.run_dir
|
parsed = self.parent, self.seed, self.run_dir
|
||||||
self.logger.info('parsed\n{}'.format(json.dumps(parsed)))
|
self.logger.info('parsed\n{}'.format(json.dumps(parsed)))
|
||||||
|
|
||||||
scrap = self.seed
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
self.logger.info('execute\n{}'.format(
|
self.execute(self.parent, self.seed, self.run_dir)
|
||||||
json.dumps((self.parent, scrap, self.run_dir))
|
paths = sorted(os.listdir(self.run_dir))
|
||||||
))
|
for path in paths:
|
||||||
self.execute(self.parent, scrap, self.run_dir)
|
scrap_path = os.path.join(self.run_dir, path)
|
||||||
|
if os.path.isfile(scrap_path):
|
||||||
path = self.scrap_recent(run_dir)
|
self.execute(
|
||||||
if path:
|
self.parent,
|
||||||
scrap = path
|
scrap_path,
|
||||||
|
self.run_dir
|
||||||
|
)
|
||||||
|
|
||||||
def scrap_recent(self, run_dir):
|
def scrap_recent(self, run_dir):
|
||||||
scraps = sorted(os.listdir(run_dir))
|
scraps = sorted(os.listdir(run_dir))
|
||||||
|
@ -53,18 +48,32 @@ class Sins():
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, parent, seed, cwd):
|
def execute(self, parent, scrap, cwd):
|
||||||
subprocess.run([parent, seed], cwd=cwd)
|
self.logger.info('execute\n{}'.format(
|
||||||
|
json.dumps((parent, scrap, cwd))
|
||||||
|
))
|
||||||
|
subprocess.run([parent, scrap], cwd=cwd)
|
||||||
|
|
||||||
|
|
||||||
def hex_dumps(scrap_dir):
|
def hex_dumps(scrap_dir):
|
||||||
scrap_dir = os.path.abspath(scrap_dir)
|
scrap_dir = os.path.abspath(scrap_dir)
|
||||||
|
dump_dir = os.path.join(scrap_dir, 'hexdumps')
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir(dump_dir)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
scraps = os.listdir(scrap_dir)
|
scraps = os.listdir(scrap_dir)
|
||||||
|
|
||||||
for scrap in scraps:
|
for scrap in scraps:
|
||||||
if '.hex' not in scrap:
|
scrap_path = os.path.join(scrap_dir, scrap)
|
||||||
scrap = os.path.join(scrap_dir, scrap)
|
hex_name = '{}.hex'.format(scrap)
|
||||||
out = os.path.join(scrap_dir, '{}.hex'.format(scrap))
|
hex_path = os.path.join(dump_dir, hex_name)
|
||||||
with open(scrap, 'rb') as file_in, open(out, 'w') as file_out:
|
|
||||||
|
if os.path.isfile(scrap_path):
|
||||||
|
with open(scrap_path, 'rb') as file_in:
|
||||||
|
with open(hex_path, 'w') as file_out:
|
||||||
binary = bytes(file_in.read())
|
binary = bytes(file_in.read())
|
||||||
for each in binary:
|
for each in binary:
|
||||||
file_out.writelines('\'\\x{:02X}\',\n'.format(each))
|
file_out.writelines('\'\\x{:02X}\',\n'.format(each))
|
||||||
|
@ -73,14 +82,29 @@ def hex_dumps(scrap_dir):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
logging.basicConfig(filename='sins.log', level=logging.DEBUG)
|
logger = logging.getLogger()
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
file_handler = logging.FileHandler(filename='sins.log')
|
||||||
|
formatter = logging.Formatter(
|
||||||
|
'#%(asctime)s %(name)s %(levelname)s\n##%(message)s\n'
|
||||||
|
)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-seed', default='build/scrap.asm.2.o')
|
parser.add_argument('-seed', default='build/scrap.asm.2.o')
|
||||||
parser.add_argument('-parent', default='build/sins')
|
parser.add_argument('-parent', default='build/sins')
|
||||||
parser.add_argument('-dir', default='sandbox')
|
parser.add_argument('-dir', default='sandbox')
|
||||||
parser.add_argument('-dumps', action='store_true')
|
parser.add_argument('-dumps', action='store_true')
|
||||||
|
parser.add_argument('-build', action='store_true')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.build:
|
||||||
|
waf = ['python3', 'waf.py', 'configure', 'build']
|
||||||
|
waf_proc = subprocess.run(waf, stdout=subprocess.PIPE)
|
||||||
|
logger.info(waf_proc.stdout)
|
||||||
|
|
||||||
if args.dumps:
|
if args.dumps:
|
||||||
hex_dumps(args.dir)
|
hex_dumps(args.dir)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue