run loop for generation

master
JoYo 2016-07-20 22:39:43 -04:00
parent 96d22098df
commit b9edd23af1
2 changed files with 24 additions and 26 deletions

View File

@ -122,7 +122,7 @@ int main(int argc, const char **argv)
return_value = generation(hex_string, rand_offset, rand_flip); return_value = generation(hex_string, rand_offset, rand_flip);
if (return_value) if (return_value)
{ {
exit(1); exit(0);
} }
} }

48
run.py
View File

@ -12,10 +12,6 @@ class Sins():
logger = logging.getLogger() logger = logging.getLogger()
def __init__(self, parent, seed=None, run_dir=None): def __init__(self, parent, seed=None, run_dir=None):
self.logger.info('run: {}'.format((
(parent, seed, run_dir))
))
self.parent = os.path.abspath(parent) self.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.')
@ -32,31 +28,22 @@ class Sins():
shutil.copy2(self.seed, self.run_dir) shutil.copy2(self.seed, self.run_dir)
parsed = self.parent, self.seed, self.run_dir parsed = (self.parent, self.seed, self.run_dir)
self.logger.info('parsed\n {}'.format((parsed))) self.logger.info('init path: {}'.format(parsed))
paths = (self.seed) paths = (self.seed,)
while True: while True:
for path in paths: for path in paths:
scrap_path = os.path.join(self.run_dir, path) scrap_path = os.path.join(self.run_dir, path)
if os.path.isfile(scrap_path): if os.path.isfile(scrap_path):
with open(scrap_path, 'rb') as scrap_file:
scrap_bin = scrap_file.read()
scrap_hex = binascii.b2a_hex(scrap_bin).upper()
child = self.generation( child = self.generation(
self.parent, self.parent,
scrap_hex, scrap_path,
str(random.randint(0, len(scrap_hex))),
str(random.randint(0, 255)),
self.run_dir self.run_dir
) )
if child: if child:
raise Exception(child) print(child)
# paths = sorted(os.listdir(self.run_dir))
paths = sorted(os.listdir(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))
@ -66,18 +53,27 @@ class Sins():
return None return None
def generation(self, parent, scrap, offset, flip, cwd): def generation(self, parent, scrap, cwd):
with open(scrap, 'rb') as scrap_file:
scrap_bin = scrap_file.read()
scrap_hex = binascii.b2a_hex(scrap_bin).upper()
offset = random.randint(0, len(scrap_hex))
flip = random.randint(0, 255)
self.logger.debug( self.logger.debug(
'generation: {}'.format((parent, scrap, offset, flip, cwd)) 'generation: {}'.format((parent, scrap_hex, offset, flip, cwd))
) )
proc = subprocess.run( proc = subprocess.run(
[parent, scrap, offset, flip], [parent, scrap_hex, str(offset), str(flip)],
cwd=cwd, cwd=cwd,
stdout=subprocess.PIPE stdout=subprocess.PIPE
) )
children = proc.stdout
return children if proc.stdout:
child_hex = binascii.a2b_hex(proc.stdout)
return child_hex
def hex_dumps(scrap_dir): def hex_dumps(scrap_dir):
@ -127,7 +123,7 @@ if __name__ == '__main__':
logger = logging.getLogger() logger = logging.getLogger()
formatter = logging.Formatter( formatter = logging.Formatter(
'#%(asctime)s %(levelname)s\n##%(message)s\n' '# %(asctime)s %(levelname)s\n%(message)s\n'
) )
if args.verbose: if args.verbose:
@ -146,6 +142,8 @@ if __name__ == '__main__':
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
logger.info('run: {}'.format(args))
if args.provision: if args.provision:
provision = ['sudo', 'sh', 'provision-ubuntu.sh'] provision = ['sudo', 'sh', 'provision-ubuntu.sh']
prov_proc = subprocess.run(provision) prov_proc = subprocess.run(provision)