def run_command(self, args): poolname, fext = path.splitext(args.filename) args.prop_d = {'name': poolname,} if args.save: args = self._mkpool_from_args(args) if args.profile: args = self._parse_cfg_to_args(args) # instantiate a new MScreen and draw to file no matter what... ms = PyMScreen(args) ms.gen_to_file(args.filename) print "Generating Mandelbrot set to\n--> {} ...\n".format(args.filename) print ms.get_info()
def mpoint_pick_random(self, key_t, lts=False): """ A function to pick a random point from a pool (MScreen). Takes a complete ConfigManager instance as 'self'. Parameter 'key_t' is really just 'poolkey' or 'privkey', but the function treats only 'poolkey' special. (Other key types besides 'privkey' are imaginable.) Returns an Argument object containing an MPoint instance, log, and error string. """ from os import path from mbrat.lib.mscreen import PyMScreen errstr = "" logstr = clogger( "\nPicking a random {} key-point ...".format(key_t), lts ) # current public pool config needed no matter what... pool_cfg = self.secmgr['pool'] # public poolkey pool or not? (ie, privkey pool) if 'pool' in key_t: pool_t = 'pool' additers = 0 keypool_cfg = pool_cfg else: pool_t = key_t additers = pool_cfg.get('iters') keypool_cfg = self.secmgr[key_t] keypool_cfg.set_section_to('pool') keypool_cfg.read() args = keypool_cfg.get_as_args() args.iters = int(args.iters) + int(additers) ms = PyMScreen(args) logstr += clogger( ms.get_info(), lts ) imgf = keypool_cfg.get('image') if not imgf or not path.exists(imgf): # generate pool image file from MScreen and attach to config file ... imgf = path.join( keypool_cfg.rootd, "{}.png".format(keypool_cfg.get('name')) ) logstr += clogger( "==> {} image not found. Making new one at\n".format(key_t) + " -> {} ...".format(imgf), lts ) ms.gen_to_file(imgf) keypool_cfg.set_write( {'image': imgf,} ) else: # ... else read PyMScreen object from image file logstr += clogger( "Reading image file ...", lts ) try: ms.gen_mscreen_from_img(imgf) except Exception, err: errstr = clogger( "\n==> ERROR: {}".format(str(err)), lts )
def run_pkrand(self, args): """ A *key-only method to pick a random point from a pool (MScreen). """ print "Picking a random {} key-point ...".format(self.name) pool_cfg = self.cfgmgr.secmgr['pool'] # public poolkey pool or not? (ie, privkey pool) if 'pool' in self.name: pool_t = 'pool' additers = 0 keypool_cfg = pool_cfg else: pool_t = self.name additers = pool_cfg.get('iters') keypool_cfg = self.config keypool_cfg.set_section_to('pool') keypool_cfg.read() args = keypool_cfg.get_as_args() args.iters = int(args.iters) + int(additers) ms = PyMScreen(args) print ms.get_info() imgf = keypool_cfg.get('image') if not imgf or not path.exists(imgf): # generate pool image file from MScreen and attach to config file ... imgf = path.join( keypool_cfg.rootd, "{}.png".format(keypool_cfg.get('name')) ) print "==> {} pool image not found. Making new at".format(self.name) print "--> {} ...".format(imgf) ms.gen_to_file(imgf) keypool_cfg.set_write( {'image': imgf,} ) else: # ... else read PyMScreen object from image file print "Reading image file ..." try: ms.gen_mscreen_from_img(imgf) except Exception, err: exit( "==> ERROR: {}".format(str(err)) )
def mpoint_pick_random(self, key_t, lts=False): """ A function to pick a random point from a pool (MScreen). Takes a ConfigManager instance as 'self'. Parameter 'key_t' is just 'poolkey' or 'privkey', but the function treats 'poolkey' special. (Other key types besides 'privkey' are imaginable.) Returns an Arguments object containing an MPoint, and log/error strings. """ from mbrat.lib.mscreen import PyMScreen errstr = "" logstr = clogger( "\nPicking a random {} key-point ...".format(key_t), lts ) # current public pool config needed no matter what... pool_cfg = self.secmgr['pool'] # public poolkey pool or not? (ie, privkey pool) if 'pool' in key_t: pool_t = 'pool' additers = 0 keypool_cfg = pool_cfg else: pool_t = key_t additers = pool_cfg.get('iters') keypool_cfg = self.secmgr[key_t] keypool_cfg.set_section_to('pool') keypool_cfg.read() args = keypool_cfg.get_as_args() args.iters = int(args.iters) + int(additers) ms = PyMScreen(args) logstr += clogger( ms.get_info(), lts ) imgf = keypool_cfg.get('image') if not imgf or not path.exists(imgf): # generate pool image file from MScreen and attach to config file ... imgf = path.join( keypool_cfg.rootd, "{}.png".format(keypool_cfg.get('name')) ) logstr += clogger( "==> {} image not found. Making new one at\n".format(key_t) + " -> {} ...".format(imgf), lts ) ms.gen_to_file(imgf) keypool_cfg.set_write( {'image': imgf,} ) else: # ... else read PyMScreen object from image file logstr += clogger( "Reading image file ...", lts ) try: ms.gen_mscreen_from_img(imgf) except Exception as err: errstr = clogger( "\n==> ERROR: {}".format(str(err)), lts ) # MScreen method returns a random MPoint object pt = ms.get_mpoint() logstr += clogger( "\n==> Point picked: ({0}, {1})\n".format( pt.C.real, pt.C.imag ) + " -> Index: [{0}, {1}]".format( pt.Get_ix(), pt.Get_iy() ), lts ) # update current *key config file self.secmgr[key_t].reset_section() self.secmgr[key_t].set_write( {'real': pt.C.real, 'imag': pt.C.imag, 'ix': pt.Get_ix(), 'iy': pt.Get_iy(), 'info': "Randomly selected key-point.",} ) self.secmgr[key_t].read() return Arguments( {'log': logstr, 'err': errstr, 'mpoint': pt} )