Exemplo n.º 1
0
    def find_log_file(self, wdir_prefix=".."):
        """
        Try to find the game log file
        Returns a string path, or None if we couldn't find it
        """
        logfile_location = ""
        version_path_fragment = Options().game_version
        if version_path_fragment == "Antibirth":
            version_path_fragment = "Rebirth"

        if platform.system() == "Windows":
            logfile_location = os.environ['USERPROFILE'] + '/Documents/My Games/Binding of Isaac {}/'
        elif platform.system() == "Linux":
            logfile_location = os.getenv('XDG_DATA_HOME',
                                         os.path.expanduser('~') + '/.local/share') + '/binding of isaac {}/'
            version_path_fragment = version_path_fragment.lower()
        elif platform.system() == "Darwin":
            logfile_location = os.path.expanduser('~') + '/Library/Application Support/Binding of Isaac {}/'

        logfile_location = logfile_location.format(version_path_fragment)

        for check in (wdir_prefix + '../log.txt', logfile_location + 'log.txt'):
            if os.path.isfile(check):
                return check

        self.log.error("Couldn't find log.txt in " + logfile_location)
        return None
Exemplo n.º 2
0
 def download_file(self, url, path):
     ''' Downloads an single url. '''
     o = Options()
     o.add_option('--output-document', path)
     self.url = url
     self.prepare_command(o)
     self._download_file(url, path)
Exemplo n.º 3
0
def fill_option_data(frame):
    """
    This collects all call options data near the stock price.

    NOTE
    ----
    If this breaks in the options data it is beacuse I changed the file.
    in my pandas installation. See the class in the local options.py.
    """
    ticks = frame.index

    out = pd.DataFrame()

    for tick in range(1, ticks.size):
        try:
            new = Options(ticks[tick]).get_forward_data(plus, call=True,
                                                        put=False, near=True,
                                                        above_below=2)
            new.index = [ticks[tick]] * new.index.size
            cat = new[['Strike', 'Expiry', 'Last', 'Vol', 'Open Int']]
            out = pd.concat([out, cat])
        except:
            pass

    return out
Exemplo n.º 4
0
 def __init__(self):
     from cli_options_parser import parser
     
     Options.__init__(self)
     opts, args = parser.parse_args()
     self.options = opts.__dict__
     self.options['path'] = [os.path.normpath(path) for path in args]
Exemplo n.º 5
0
 def _get_prefs_data(self, req, opts=None):
     """Returns the pref data, a dict of rule class titles whose values
     include lists of rule spec preference dicts each with these keys:
     
       id (based on unique key)
       label (of checkbox)
       enabled ('1' or '0')
       type ('none', 'select', or 'text') 
       options (list of options if type is 'select')
       value (saved preference or default value)
     """
     if opts is None:
         opts = Options(self.env)
     data = {}
     for rule in self.rules:
         for key in opts:
             if not opts.has_pref(key):
                continue
             target_re = re.compile(r"(?P<target>[^.]+).*")
             target = target_re.match(key).groupdict()['target']
             trigger = rule.get_trigger(req, target, key, opts)
             if not trigger:
                 continue
             
             # this rule spec has a pref - so get it!
             pref = opts.get_pref(req, target, key)
             rule.update_pref(req, trigger, target, key, opts, pref)
             data.setdefault(rule.title,{'desc':rule.desc,'prefs':[]})
             data[rule.title]['prefs'].append(pref)
     return data
Exemplo n.º 6
0
    def __init__(self, executable_path="chromedriver", port=0,
                 chrome_options=None, service_args=None,
                 desired_capabilities=None):
        """
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - desired_capabilities: Dictionary object with non-browser specific
           capabilities only, such as "proxy" or "loggingPref".
         - chrome_options: this takes an instance of ChromeOptions
        """
        if chrome_options is None:
            options = Options()
        else:
            options = chrome_options

        if desired_capabilities is not None:
          desired_capabilities.update(options.to_capabilities())
        else:
          desired_capabilities = options.to_capabilities()

        self.service = Service(executable_path, port=port, service_args=service_args)
        self.service.start()

        try:
            RemoteWebDriver.__init__(self,
                command_executor=self.service.service_url,
                desired_capabilities=desired_capabilities)
        except:
            self.quit()
            raise 
Exemplo n.º 7
0
    def __init__(self, executable_path="chromedriver", port=0,
                 desired_capabilities=None, chrome_options=None):
        """
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various chrome
           switches). This is being deprecated, please use chrome_options
         - chrome_options: this takes an instance of ChromeOptions
        """
        if chrome_options is None:
            options = Options()
        else:
            options = chrome_options

        if desired_capabilities is not None:
            warnings.warn("Desired Capabilities has been deprecated, please user chrome_options.", DeprecationWarning)
            desired_capabilities.update(options.to_capabilities())
        else:
            desired_capabilities = options.to_capabilities()

        self.service = Service(executable_path, port=port)
        self.service.start()

        try:
            RemoteWebDriver.__init__(self,
                command_executor=self.service.service_url,
                desired_capabilities=desired_capabilities)
        except:
            self.quit()
            raise WebDriverException("The Driver was not able to start.")
Exemplo n.º 8
0
 def download_new_files(self, downloader, episodes):
     logging.info("Subscriptions.download_new_files")
     queue = self.prepare_queue(episodes)
     if len(queue) > 0:
         o = Options()
         o.add_option('--directory-prefix', self._data_subdir())
         if self.limitrate:
             o.add_option('--limit-rate',
                                   self.limitrate)
         downloader.download_queue(queue, o)
Exemplo n.º 9
0
 def load_options(self):
     #realkeydict
     self.rkd = {}
     options = Options()
     for dkey, rkey in options.iteritems():
         try:
             self.rkd[dkey] = key.__getattribute__(rkey)
         except AttributeError:
             if rkey == 'M1':
                 self.rkd[dkey] = 1 + self.mouse_offset
Exemplo n.º 10
0
 def __init__(self, profile='default'):
     Options.__init__(self)
     
     if _PROFILES is not None:
         try:
             opts, args = parser.parse_args(shlex.split(_PROFILES[profile]))
             self.options = opts.__dict__
             self.options['path'] = args
         except KeyError:
             if profile != 'default':
                 sys.stderr.write("Error: there is no profile with name '%s'\n" % profile)
                 sys.exit()
Exemplo n.º 11
0
def ctmain():
    utils.fix_output_encoding()
    settings = ComicTaggerSettings()

    opts = Options()
    opts.parseCmdLineArgs()

    # manage the CV API key
    if opts.cv_api_key:
        if opts.cv_api_key != settings.cv_api_key:
            settings.cv_api_key = opts.cv_api_key
            settings.save()
    if opts.only_set_key:
        print("Key set")
        return

    ComicVineTalker.api_key = settings.cv_api_key

    signal.signal(signal.SIGINT, signal.SIG_DFL)

    if not qt_available and not opts.no_gui:
        opts.no_gui = True
        print >> sys.stderr, "PyQt4 is not available.  ComicTagger is limited to command-line mode."

    if opts.no_gui:
        cli.cli_mode(opts, settings)
    else:
        app = QtGui.QApplication(sys.argv)

        if platform.system() != "Linux":
            img = QtGui.QPixmap(ComicTaggerSettings.getGraphic('tags.png'))

            splash = QtGui.QSplashScreen(img)
            splash.show()
            splash.raise_()
            app.processEvents()

        try:
            tagger_window = TaggerWindow(opts.file_list, settings, opts=opts)
            tagger_window.show()

            if platform.system() != "Linux":
                splash.finish(tagger_window)

            sys.exit(app.exec_())
        except Exception as e:
            QtGui.QMessageBox.critical(
                QtGui.QMainWindow(),
                "Error",
                "Unhandled exception in app:\n" +
                traceback.format_exc())
Exemplo n.º 12
0
    def __init__(self):
        super().__init__()
   
        self.option_add("*tearOff", FALSE)
        self.initialized = False
        self.title("Papyer")
        
        x, y = 1500, 500
        self.minsize(x, y)
        placeWindow(self, x, y)
        
        self.options = Options(self)
        self["menu"] = TopMenu(self)        

        self.protocol("WM_DELETE_WINDOW", self.closeFun)

        self.base = os.getcwd()

        self.selectVar = StringVar()
        self.searchVar = StringVar()

        self.createWidgets()

        self.columnconfigure(1, weight = 1)
        self.columnconfigure(3, weight = 1)
        self.columnconfigure(5, weight = 1)
        self.rowconfigure(4, weight = 1)

        self.bind("<Control-d>", lambda e: self.filetree.keepDuplicates())
        self.bind("<Control-a>", lambda e: self.filetree.selectAll())
        
        self.mainloop()
Exemplo n.º 13
0
class PyvisdkApp(object):
    '''
    Base class implementation of a command line application.  See the :py:mod:`~pyvisdk.app` module for documentation on the format of the options file.
    '''


    def __init__(self, usage=None):
        '''
        Constructor
        '''
        self.options = Options()
        if not usage:
            usage = "usage: %prog [options]"
        self.parser = OptionParser(usage=usage)
        self.parser.add_option("-c", "--config", dest="VI_CONFIG", help="Specify non-default name or location for the VI Perl Toolkit configuration file. Default name and location for Linux is ~/.visdkrc and for Windows is %HOME%\visdk.rc.")
        self.parser.add_option("-p", "--password", dest="VI_PASSWORD", help="Password for the specified username. Sucessful authentication with username and password returns a session object that can be saved and used for subsequent connections using the same or different script. See sessionfile.")
        self.parser.add_option("--portnumber", dest="VI_PORTNUMBER", help="Port used for server connection.")
        self.parser.add_option("--protocol", dest="VI_PROTOCOL", help="Protocol used to connect to server. Default is HTTPS. If the server has been configured for HTTP, set to HTTP. ")
        self.parser.add_option("-s", "--server", dest="VI_SERVER", help="ESX Server or VirtualCenter Management Server host to which you want the application or script to connect. Default is localhost if none specified.")
        self.parser.add_option("--servicepath", dest="VI_SERVICEPATH", help="Service path for server connection. Default is /sdk/webService.")
        self.parser.add_option("--sessionfile", dest="VI_SESSIONFILE", help="Name of file containing the token saved from successful login. Alternative to specifying username and password. Sessions time out after 30 minutes of inactivity.")
        self.parser.add_option("--url", dest="VI_URL", help="Complete URL for SDK connection. An alternative to specifying protocol, server, and servicepath as individual connection parameters. For example, python app_name.py --url https://myserver.mycompany.com/sdk --username root --password mypassword")
        self.parser.add_option("-u", "--username", dest="VI_USERNAME", help="User account that has privileges to connect to the server.")
        self.parser.add_option("-v", "--verbose", dest="VI_VERBOSE", help="Increase loglevel. Use in conjunction with Util::trace subroutine to display additional debugging information. By default, value of --verbose (loglevel) is 0. ")
        self.parser.add_option("-V", "--version", help="Displays script version information, if available.")
        
    def parse(self):
        (cmd_opts, _) = self.parser.parse_args(sys.argv[1:]) # IGNORE W0201
        
        # load up options from the visdkrc file if there is any
        if cmd_opts.VI_CONFIG:
            self.options.load(cmd_opts.VI_CONFIG)
        else:
            self.options.load()
            
        # also, update options with environmental values, overriding those in the configuration file.
        self.options.load_env()
            
        # update our options with what was entered on the command line.  This will override previously
        # entered options
        for name, value in cmd_opts.__dict__.items():
            if value:
                self.options.update({name:value})
        
        # need to have server, username, and password or fail
        if not (self.options.VI_USERNAME and self.options.VI_PASSWORD and self.options.VI_SERVER):
            raise RuntimeError("Must specify --username, --password and --server")


    def connect(self):
        self.vim = Vim(self.options.VI_SERVER)
        self.vim.login(self.options.VI_USERNAME, self.options.VI_PASSWORD)
    
    def disconnect(self):
        self.vim.logout()
Exemplo n.º 14
0
    def userFolder():
        opts = Options()
        opts.parseCmdLineArgs(False)
        
        filename_encoding = sys.getfilesystemencoding()

        if opts.user_dir is not None:
            folder = opts.user_dir
        elif platform.system() == "Windows":
            folder = os.path.join( AppFolders.windowsAppDataFolder(), appname )
        elif platform.system() == "Darwin":
            folder = os.path.join( os.path.expanduser('~') , 'Library/Application Support/'+appname)
        else:
            folder = os.path.join( os.path.expanduser('~') , '.'+appname)
            
        if folder is not None:
            folder = folder.decode(filename_encoding)
        return folder
Exemplo n.º 15
0
    def userFolder():

        opts = Options()
        opts.parseCmdLineArgs()

        filename_encoding = sys.getfilesystemencoding()

        if opts.user_dir is not None:
            folder = opts.user_dir
        elif platform.system() == "Windows":
            folder = os.path.join(AppFolders.windowsAppDataFolder(), "ComicStreamer")
        elif platform.system() == "Darwin":
            folder = os.path.join(os.path.expanduser("~"), "Library/Application Support/ComicStreamer")
        else:
            folder = os.path.join(os.path.expanduser("~"), ".ComicStreamer")

        if folder is not None:
            folder = folder.decode(filename_encoding)
        return folder
Exemplo n.º 16
0
    def load_configuration(self):
        self.options = Options.from_file(Spaz.OPTIONS_FILE)
        if not self.options.ok:
            sys.exit(1)

        self.parse_args()
        self.configuration = Configuration.from_file(self.options.config_file)
        if not self.configuration.ok:
            sys.exit(1)
        if self.args.validate:
            # just validate configuration
            logging.getLogger(__name__).info("Validated: OK")
            sys.exit(0)
Exemplo n.º 17
0
 def __init__(self):
     self.main = Corrector()
     self.match = ""
     self.matchgeo = ""
     self.commands = []
     self.option = Options()
     self.display = Chunks("")
     self.display.create_Chunks()
     self.last_Display = ""
     self.find = Chunks("")
     self.find.create_Chunks()
     self.table = Outline()
     self.location_History = {}
Exemplo n.º 18
0
 def process(self,command):
     opts = [];self.main.disting(command)
     for i in self.main.cur()['words']+self.main.cur()['splits']:
         for j in self.main.match(i):
             if j[0]=='None':
                 continue
             if j[1]==0:
                 try:
                     k = self.main.cur()['words'].index(i)
                     self.main.cur()['words'][k] = j[0]
                 except:
                     self.main.cur()['words'].append(j[0])
                 continue
                     
             if opts == []:
                 opts = Options()
             opts.add_Option(content="{0}".format(j[0]))
         
         if opts:
             return [self.main.cur()['words'],self.main.history],opts,i
             
     return [self.main.cur()['words'],self.main.history],opts,""
Exemplo n.º 19
0
class DisplayPanel(object):

	def __init__(self, surface, pos, player, images):
		self.surface = surface
		self.pos = pos
		self.player = player
		self.images = images
		
		self.optionsPos = (0,0)
		self.optionsRect = pygame.Rect(self.optionsPos, (Cell.size * 12, Cell.size * 6))
		self.options = Options(self.surface.subsurface(self.optionsRect), self.optionsPos, self.player, images)
		
		self.statusPos = (0, Cell.size * 6 + Cell.size)
		self.statusRect = pygame.Rect(self.statusPos, (Cell.size * 12, Cell.size))
		self.status = Status(self.surface.subsurface(self.statusRect), self.statusPos, self.player, images)
		
		self.logPos = (0, Cell.size * 7 + (Cell.size * 2))
		self.logRect = pygame.Rect(self.logPos, (Cell.size * 12, Cell.size * 8))
		self.log = Output(self.surface.subsurface(self.logRect), self.logPos, self.player.log)
		
		
	def draw(self):
		self.options.draw()
		self.status.draw()
		self.log.draw()
		
	def notify(self, pos, event):
		vec = Vector2(pos)
		vec -= self.pos
		
		point = (int(vec[0]), int(vec[1]))
		if self.optionsRect.collidepoint(point):
			self.options.notify(point, event)
			
		if self.statusRect.collidepoint(point):
			self.status.notify(point, event)
			
		if self.logRect.collidepoint(point):
			self.log.notify(point, event)
Exemplo n.º 20
0
 def setup_user_session(self):
     self.tree.get_widget("user").set_markup("<b>%s</b>" % self.username)
     self.options = Options(self.username, self.usersDB)
     if not os.path.exists(self.HOME_DIR + self.username + 'DB'):
         self.write_info(_("User database doesn't exist, creating."))
         self.first_run = True
     else:
         self.first_run = False
     self.song_db = dbClass.lastfmDb(self.HOME_DIR + self.username + "DB",
                                     self.first_run)
     self.set_button_count()
     self.show_main_window()
     if self.options.return_option("startup_check") == True:
         self.on_check_device_clicked(None)
Exemplo n.º 21
0
 def _get_triggers(self, req):
     """Converts trac.ini config to dict of triggers with rule specs."""
     triggers = {}
     opts = Options(self.env)
     for key in opts:
         # extract the target field
         target_re = re.compile(r"(?P<target>[^.]+).*")
         target = target_re.match(key).groupdict()['target']
         
         # extract rule specifications from configs
         for rule in self.rules:
             trigger = rule.get_trigger(req, target, key, opts)
             if not trigger:
                 continue
             if not opts.is_enabled(req, key):
                 continue
             value,_ = opts.get_value_and_options(req, target, key)
             spec = {'rule_name':rule.name, 'trigger':trigger,
                     'target':target, 'value':value}
             rule.update_spec(req, key, opts, spec)
             triggers.setdefault(trigger, []).append(spec)
         
     return triggers
Exemplo n.º 22
0
    def __init__(self):
        self.mainloop = gobject.MainLoop()

        self.status_icon = gtk.StatusIcon()
        self.status_icon.set_from_file(TRAYICON)

        self.options = Options()

        self.ui = UiDict(os.path.join(XML, 'pyazan_ui.xml'))
        self.ui['pref_window'].set_icon_from_file(TRAYICON)
        self.attach_signals()

        self.load_options()
        self.plugin_handler = PluginGTK(self)
        gobject.timeout_add_seconds(60, self.update_tool_tip)
Exemplo n.º 23
0
    def test_verify(self):
        o = Options({})
        self.assertTrue(o.get_verify())

        dictionary = {'verify': False}
        o = Options(dictionary)
        self.assertFalse(o.get_verify())

        dictionary = {'verify': True}
        o = Options(dictionary)
        self.assertTrue(o.get_verify())
Exemplo n.º 24
0
	def __init__(self, surface, pos, player, images):
		self.surface = surface
		self.pos = pos
		self.player = player
		self.images = images
		
		self.optionsPos = (0,0)
		self.optionsRect = pygame.Rect(self.optionsPos, (Cell.size * 12, Cell.size * 6))
		self.options = Options(self.surface.subsurface(self.optionsRect), self.optionsPos, self.player, images)
		
		self.statusPos = (0, Cell.size * 6 + Cell.size)
		self.statusRect = pygame.Rect(self.statusPos, (Cell.size * 12, Cell.size))
		self.status = Status(self.surface.subsurface(self.statusRect), self.statusPos, self.player, images)
		
		self.logPos = (0, Cell.size * 7 + (Cell.size * 2))
		self.logRect = pygame.Rect(self.logPos, (Cell.size * 12, Cell.size * 8))
		self.log = Output(self.surface.subsurface(self.logRect), self.logPos, self.player.log)
Exemplo n.º 25
0
class Controller:
    def __init__(self, options = None):
        if options and isinstance(options, Options):
            self.options = options
        else:
            self.options = Options()

    def run(self):
        parsedArgs = self.options.parse()
        scanner = Scanner(parsedArgs.path)
        duplicateCollector = DuplicateCollector()
        scanner.scan(duplicateCollector)

        if parsedArgs.verbose:
            duplicateCollector.write(True)
        else:
            duplicateCollector.write()
Exemplo n.º 26
0
 def __init__(self, usage=None):
     '''
     Constructor
     '''
     self.options = Options()
     if not usage:
         usage = "usage: %prog [options]"
     self.parser = OptionParser(usage=usage)
     self.parser.add_option("-c", "--config", dest="VI_CONFIG", help="Specify non-default name or location for the VI Perl Toolkit configuration file. Default name and location for Linux is ~/.visdkrc and for Windows is %HOME%\visdk.rc.")
     self.parser.add_option("-p", "--password", dest="VI_PASSWORD", help="Password for the specified username. Sucessful authentication with username and password returns a session object that can be saved and used for subsequent connections using the same or different script. See sessionfile.")
     self.parser.add_option("--portnumber", dest="VI_PORTNUMBER", help="Port used for server connection.")
     self.parser.add_option("--protocol", dest="VI_PROTOCOL", help="Protocol used to connect to server. Default is HTTPS. If the server has been configured for HTTP, set to HTTP. ")
     self.parser.add_option("-s", "--server", dest="VI_SERVER", help="ESX Server or VirtualCenter Management Server host to which you want the application or script to connect. Default is localhost if none specified.")
     self.parser.add_option("--servicepath", dest="VI_SERVICEPATH", help="Service path for server connection. Default is /sdk/webService.")
     self.parser.add_option("--sessionfile", dest="VI_SESSIONFILE", help="Name of file containing the token saved from successful login. Alternative to specifying username and password. Sessions time out after 30 minutes of inactivity.")
     self.parser.add_option("--url", dest="VI_URL", help="Complete URL for SDK connection. An alternative to specifying protocol, server, and servicepath as individual connection parameters. For example, python app_name.py --url https://myserver.mycompany.com/sdk --username root --password mypassword")
     self.parser.add_option("-u", "--username", dest="VI_USERNAME", help="User account that has privileges to connect to the server.")
     self.parser.add_option("-v", "--verbose", dest="VI_VERBOSE", help="Increase loglevel. Use in conjunction with Util::trace subroutine to display additional debugging information. By default, value of --verbose (loglevel) is 0. ")
     self.parser.add_option("-V", "--version", help="Displays script version information, if available.")
Exemplo n.º 27
0
	def __init__(self, parent=None):

		# 
		QtGui.QWidget.__init__(self, parent)


		
#		from PyQt4 import QString
		self.ui = Ui_Form()
		self.ui.setupUi(self, [  (_('Reset'), self.reset),
					 (_('Measuring mode'), self.setMeasuringMode),
					 (_('Distance to measure in X axis'), self.askWantedX),
					 (_('Distance to measure in Y axis'), self.askWantedY),
					 (_('Calibrate Y axis'), self.calY),
					 (_('Calibrate X axis'), self.calX),
					 (_('Finish calibration'), self.finishCal),
					 (_('Save calibration'), self.saveRatio),
					 (_('Allow calibration'), self.allowCalibrate),
					])


		
		print 'main widget: ',self.centralWidget()
		self.centralWidget().setMouseTracking(True)
		# mode of working
		self.mode = Mode(self, ("MEASURING", "CAL_X", "CAL_Y"))

		# storing programs options
		self.options = Options()

		# object that manages all other objects :)
		self.mediator = Mediator(self.cursor(), self)




		# distance the user wants the device to travel
		self.wantedX, self.wantedY = 0.0, 0.0

		self.setMeasuringMode()
		# set default values
		self.reset()
Exemplo n.º 28
0
    def test_proxy(self):
        dictionary = {}
        o = Options(dictionary)
        self.assertDictEqual({}, o.get_proxies())

        dictionary = {'proxies': {'http': 'http://*****:*****@10.10.1.10:1080'}}
        o = Options(dictionary)
        self.assertDictEqual({'http': 'http://*****:*****@10.10.1.10:1080'}, o.get_proxies())

        dictionary = {'proxies': {'http': 'http://*****:*****@10.10.1.10:1080', 'https': 'http://10.10.1.10:1080'}}
        o = Options(dictionary)
        self.assertDictEqual(
            {'http': 'http://*****:*****@10.10.1.10:1080', 'https': 'http://10.10.1.10:1080'},
            o.get_proxies()
        )
Exemplo n.º 29
0
def main(options):
    # print('__main__')
    options = Options.from_arguments(arguments)
    if options.collecting_data:
        data_collection = DataCollection(options)
        data_collection.collect_data()

    elif options.display_data:
        display(options)

    elif options.test:
        print('running tests...')
        suite = unittest.TestSuite()
        for t in [test.split('.')[0] for test in glob.glob('test_*.py')]:
            try:
                # If the module defines a suite() function, call it to get the suite.
                mod = __import__(t, globals(), locals(), ['suite'])
                suitefn = getattr(mod, 'suite')
                suite.addTest(suitefn())
            except (ImportError, AttributeError):
                # else, just load all the test cases from the module.
                suite.addTest(unittest.defaultTestLoader.loadTestsFromName(t))
        unittest.TextTestRunner().run(suite)
Exemplo n.º 30
0
    def draw_state(self, state):
        """
        Draws the state
        :param state:
        """
        if self.state != state:
            self.reset()
            self.state = state

        opt = Options()
        # Clear the screen
        self.screen.fill(DrawingTool.color(opt.background_color))

        # If state is None we just want to clear the screen
        if self.state is None:
            return

        # If items were added, or removed (run restarted) regenerate items
        if self.state.modified:
            # We picked up an item, start the counter
            self.item_picked_up()
            overlay = Overlay(self.wdir_prefix, self.state)
            overlay.update_seed()
            if len(self.drawn_items) > 0:
                overlay.update_stats()
                overlay.update_last_item_description()
        current_floor = self.state.last_floor

        # Draw item pickup text, if applicable
        # Save the previous text_height to know if we need to reflow the items
        text_height_before = self.text_height
        text_written = False
        if self.item_message_countdown_in_progress():
            if opt.show_description:
                text_written = self.write_item_text()
        else:
            self.selected_item_index = None
        if not text_written and opt.show_status_message:
            # Draw seed/guppy text:
            seed = self.state.seed

            dic = defaultdict(str,
                              seed=seed,
                              version_number=self.state.version_number,
                              room_id=self.state.room_id)
            # Update this dic with player stats

            for stat in ItemInfo.stat_list:
                dic[stat] = Overlay.format_value(self.state.player_stats[stat])
            for transform in ItemInfo.transform_list:
                dic[transform] = Overlay.format_transform(
                    self.state.player_transforms[transform])

            # Use vformat to handle the case where the user adds an
            # undefined placeholder in default_message
            message = string.Formatter().vformat(opt.status_message, (), dic)
            self.text_height = self.write_message(message)
        elif not text_written:
            self.text_height = 0

        # We want to reflow if the state has been modified or if the text
        # height has changed
        if self.state.modified or self.text_height != text_height_before:
            self.__reflow()

        floor_to_draw = None

        idx = 0
        # Draw items on screen, excluding filtered items:
        for drawable_item in self.drawn_items:
            if floor_to_draw is None or floor_to_draw.floor != drawable_item.item.floor:
                floor_to_draw = DrawableFloor(drawable_item.item.floor,
                                              drawable_item.x, drawable_item.y,
                                              self)
            if not floor_to_draw.is_drawn and self.show_floors:
                floor_to_draw.draw()
            drawable_item.draw(selected=(idx == self.selected_item_index))

            idx += 1

        # Also draw the floor if we hit the end or if the list is empty,
        # so the current floor is visible
        if self.show_floors and current_floor is not None:
            if floor_to_draw is None or (floor_to_draw is not None and
                                         floor_to_draw.floor != current_floor):
                x, y = self.next_item
                DrawableFloor(current_floor, x, y, self).draw()

        self.state.drawn()
        pygame.display.flip()
        self.framecount += 1
Exemplo n.º 31
0
    def send_files(self, filenames=None):
        """
        Build the GUI in send files mode.
        Note that this is the only mode currently implemented.
        """
        # file selection
        self.file_selection = FileSelection()
        if filenames:
            for filename in filenames:
                self.file_selection.file_list.add_file(filename)

        # server status
        self.server_status = ServerStatus(self.qtapp, self.app, web,
                                          self.file_selection)
        self.server_status.server_started.connect(
            self.file_selection.server_started)
        self.server_status.server_started.connect(self.start_server)
        self.server_status.server_stopped.connect(
            self.file_selection.server_stopped)
        self.server_status.server_stopped.connect(self.stop_server)
        self.start_server_finished.connect(self.clear_message)
        self.start_server_finished.connect(
            self.server_status.start_server_finished)
        self.stop_server_finished.connect(
            self.server_status.stop_server_finished)
        self.file_selection.file_list.files_updated.connect(
            self.server_status.update)
        self.server_status.url_copied.connect(self.copy_url)
        self.starting_server_step2.connect(self.start_server_step2)

        # filesize warning
        self.filesize_warning = QtGui.QLabel()
        self.filesize_warning.setStyleSheet(
            'padding: 10px 0; font-weight: bold; color: #333333;')
        self.filesize_warning.hide()

        # downloads
        self.downloads = Downloads()

        # options
        self.options = Options(web, self.app)

        # status bar
        self.status_bar = QtGui.QStatusBar()
        self.status_bar.setSizeGripEnabled(False)

        # main layout
        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(self.file_selection)
        self.layout.addLayout(self.server_status)
        self.layout.addWidget(self.filesize_warning)
        self.layout.addLayout(self.downloads)
        self.layout.addLayout(self.options)
        self.layout.addWidget(self.status_bar)
        self.setLayout(self.layout)
        self.show()

        # check for requests frequently
        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"),
                               self.check_for_requests)
        self.timer.start(500)
Exemplo n.º 32
0
import numpy as np
import torchvision
from torchvision.datasets import MNIST
from torchvision.transforms import ToTensor

from options import Options


# dataset
class ToNumpy(object):
    def __call__(self, sample):
        return np.array(sample)


def load_mnist_dataset(dataset_path, download=False, train=True):
    dataset = MNIST(root=dataset_path,
                    download=download,
                    train=train,
                    transform=torchvision.transforms.Compose(
                        [ToNumpy(),
                         torchvision.transforms.ToTensor()]))
    return dataset


if __name__ == '__main__':
    cfg = Options().parse()
    dataset_path = cfg.dataset_path

    load_mnist_dataset(dataset_path=dataset_path, download=True)
Exemplo n.º 33
0
def main():

	global ROOTDIR
	global nodes
	global cores
	global target
	global nprocmax
	global nprocmin

	# Parse command line arguments
	args   = parse_args()

	# Extract arguments
	ntask = args.ntask
	nodes = args.nodes
	cores = args.cores
	nprocmin_pernode = args.nprocmin_pernode
	machine = args.machine
	optimization = args.optimization
	nruns = args.nruns
	truns = args.truns
	# JOBID = args.jobid
	TUNER_NAME = args.optimization
	os.environ['MACHINE_NAME'] = machine
	os.environ['TUNER_NAME'] = TUNER_NAME


	nprocmax = nodes*cores-1  # YL: there is one proc doing spawning, so nodes*cores should be at least 2
	nprocmin = min(nodes*nprocmin_pernode,nprocmax-1)  # YL: ensure strictly nprocmin<nprocmax, required by the Integer space
	# matrices = ["big.rua", "g4.rua", "g20.rua"]
	matrices = ["nimrodMatrix-V.bin", "nimrodMatrix-B.bin", "cg20.cua"]
	# matrices = ["Si2.rb", "SiH4.rb", "SiNa.rb", "Na5.rb", "benzene.rb", "Si10H16.rb", "Si5H12.rb", "SiO.rb", "Ga3As3H12.rb", "GaAsH6.rb", "H2O.rb"]
	# Task parameters
	matrix    = Categoricalnorm (matrices, transform="onehot", name="matrix")
	# Input parameters
	COLPERM   = Categoricalnorm (['2', '4'], transform="onehot", name="COLPERM")
	LOOKAHEAD = Integer     (5, 20, transform="normalize", name="LOOKAHEAD")
	nprows    = Integer     (1, nprocmax, transform="normalize", name="nprows")
	nproc     = Integer     (nprocmin, nprocmax, transform="normalize", name="nproc")
	NSUP      = Integer     (30, 300, transform="normalize", name="NSUP")
	NREL      = Integer     (10, 40, transform="normalize", name="NREL")	
	factor   = Real        (float("-Inf") , float("Inf"), name="factor_time")
	solve    = Real        (float("-Inf") , float("Inf"), name="solve_time")
	IS = Space([matrix])
	PS = Space([COLPERM, LOOKAHEAD, nproc, nprows, NSUP, NREL])
	OS = Space([factor, solve])
	cst1 = "NSUP >= NREL"
	cst2 = "nproc >= nprows" # intrinsically implies "p <= nproc"
	constraints = {"cst1" : cst1, "cst2" : cst2}
	models = {}

	""" Print all input and parameter samples """	
	print(IS, PS, OS, constraints, models)

	problem = TuningProblem(IS, PS, OS, objectives, constraints, None)
	computer = Computer(nodes = nodes, cores = cores, hosts = None)  

	""" Set and validate options """	
	options = Options()
	options['model_processes'] = 1
	# options['model_threads'] = 1
	options['model_restarts'] = 1
	# options['search_multitask_processes'] = 1
	# options['model_restart_processes'] = 1
	options['distributed_memory_parallelism'] = False
	options['shared_memory_parallelism'] = False
	options['model_class '] = 'Model_LCM'
	options['verbose'] = False
	options['search_algo'] = 'nsga2' #'maco' #'moead' #'nsga2' #'nspso' 
	options['search_pop_size'] = 1000 # 1000
	options['search_gen'] = 10
	options['search_more_samples'] = 4
	options.validate(computer = computer)

	""" Intialize the tuner with existing data"""		
	data = Data(problem)
	gt = GPTune(problem, computer = computer, data = data, options = options)

	if(TUNER_NAME=='GPTune'):
		#""" Building MLA with NI random tasks """
		#NI = ntask
		#NS = nruns
		#(data, model,stats) = gt.MLA(NS=NS, NI=NI, NS1 = max(NS//2,1))
		#print("stats: ",stats)

		""" Building MLA with the given list of tasks """	
		#giventask = [["big.rua"], ["g4.rua"], ["g20.rua"]]	
		giventask = [["cg20.cua"]]	
		# giventask = [["nimrodMatrix-V.bin"]]	
		NI = len(giventask)
		NS = nruns
		(data, model,stats) = gt.MLA(NS=NS, NI=NI, Igiven =giventask, NS1 = max(NS//2,1))
		print("stats: ",stats)


		""" Print all input and parameter samples """	
		for tid in range(NI):
			print("tid: %d"%(tid))
			print("    matrix:%s"%(data.I[tid][0]))
			print("    Ps ", data.P[tid])
			print("    Os ", data.O[tid])
			ndf, dl, dc, ndr = pg.fast_non_dominated_sorting(data.O[tid])
			front = ndf[0]
			# print('front id: ',front)
			fopts = data.O[tid][front]
			xopts = [data.P[tid][i] for i in front]
			print('    Popts ', xopts)		
			print('    Oopts ', fopts)		
Exemplo n.º 34
0
                          drop_last=False)
    return train_dl, valid_dl


if __name__ == '__main__':

    # from options import Options
    # opt = Options().parse()
    # # samples = pickle_loader("../data/watch-n-bot/fridge_k1/out/data_01-05-11.pkl")
    #
    # tr, va = build_dataloader(opt)
    # dataloader = {'train': tr, 'valid': va}

    from options import Options
    import cv2
    opt = Options().parse()
    opt.batch_size = 5
    # opt.data_dir = '../data/watch-n-bot/fridge_k1/sequence'

    tr, vl = build_dataloader(opt)

    for index, (a, b) in enumerate(tr):
        # a: 5 x 10 x c x w x h
        # imgs = a[0].unbind(0)
        # imgs = list(map(lambda x: (x.permute([1, 2, 0]).numpy()*255).squeeze().astype(np.uint8), imgs))
        # for index, img in enumerate(imgs):
        #     cv2.imwrite('l_{}.png'.format(index), img)
        #     exit(1)

        print(index)
        print(a.shape)
Exemplo n.º 35
0
 def tick(self):
     """ Tick the clock. """
     self.clock.tick(int(Options().framerate_limit))
Exemplo n.º 36
0
 def save_window_position(self):
     if platform.system() == "Windows":
         win_pos = self.win_info.getScreenPosition()
         Options().x_position = win_pos["left"]
         Options().y_position = win_pos["top"]
Exemplo n.º 37
0
from options import Options
from torchvision import datasets, models, transforms
from torchvision.datasets import ImageFolder
from torch.utils.data import DataLoader
from torchvision.utils import make_grid
from random import choice

#path = './models/cifar10_dim_128_lambda_40_zlambd_0_epochs_50.torch'
path = './models/cifar10_dim_128_lambda_40_zlambd_0_epochs_100.torch'
state_dict = torch.load(path)

model.load_state_dict(state_dict)
model.eval()

batch_size = 64
opt = Options().parse()
dataset = "NanjingRail_blocks2"
opt.batch_size = batch_size
opt.isize = 32

# dataloader = load_data(opt)

transform = transforms.Compose([
    transforms.Scale(opt.isize),
    transforms.CenterCrop(opt.isize),
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
])

dataset_train = ImageFolder('./data/{}/train'.format(dataset), transform)
dataset_train = torch.stack(list(zip(*dataset_train))[0])
Exemplo n.º 38
0
#!/usr/bin/env python
#-*- coding:utf-8 -*-

from __future__ import print_function
from anchor_wrap import anchor_call
from data import Data
from options import Options
import os
import resource
import sys
from xgbooster import XGBooster


if __name__ == '__main__':
    # parsing command-line options
    options = Options(sys.argv)

    # making output unbuffered
    if sys.version_info.major == 2:
        sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

    xgb = XGBooster(options, from_model='../temp/lending_data/lending_data_nbestim_50_maxdepth_3_testsplit_0.2.mod.pkl')

    # encode it and save the encoding to another file
    xgb.encode()

    with open('../bench/anchor/lending/lending.samples', 'r') as fp:
        lines = fp.readlines()

    # timers
    atimes = []
Exemplo n.º 39
0
from options import Options
import itertools
from .php5_common import generate_via_half_string_merge, php_hash

options = Options()
options.add_option('n_collisions', 10, 'Number of colliding strings to create')
options.add_option('n_substrings', 100,
                   'Number of target and zero hash substrings to use')
options.add_option('hash_table_size', 2**32, 'Size of target hash table')
options.add_option(
    'target_type', 'preimage',
    'Whether the target is an image (hash output) or preimage (hash input)',
    ['image', 'preimage'])
options.add_option('target', 'hello',
                   'Image or preimage of desired hash value')

DESCRIPTION = 'Produces hash collisions for the PHP 5 hash function. Uses a faster less memory intensive\n' + \
              '  technique but generates longer strings.  n_substrings is the number of initial target and\n' + \
              '  zero strings to generate which will then be combined to create the desired number of collisions.\n' + \
              '  By setting this to larger values more time and memory is required but smaller strings are\n' + \
              '  generated.'

DEFAULT_INPUT = 'char'


def run(generator, output):
    """Generate hash collisions in two steps: 1) generate substrings with a hash of the target and a hash of zero and 2)
        combine the strings by incrementally increasing the number of zero strings prepended."""
    forbidden_string = ''
    n_collisions = options['n_collisions']
    n_substrings = options['n_substrings']
Exemplo n.º 40
0
from options import Options
from model import SQuAD
import logging

logger = logging.getLogger(__name__)
logging.basicConfig(
    format="%(asctime)s - %(levelname)s - %(name)s -   %(message)s",
    datefmt="%m/%d/%Y %H:%M:%S",
    level=logging.INFO)

if __name__ == '__main__':
    opt = Options().parse()
    '''
   '''
    opt.model_type = "distilbert"
    #for more pretrain models, see https://github.com/huggingface/transformers/blob/b54ef78d0c30045bb3f9ecc8b178eab0dfdbeaec/docs/source/pretrained_models.rst
    opt.model_name_or_path = "distilbert-base-uncased-distilled-squad"
    opt.do_train = True
    opt.do_eval = True
    opt.do_lower_case = True
    opt.output_dir = "../models/wwm_uncased_finetuned_squad"
    opt.threads = 4

    m = SQuAD(opt)

    # do train
    global_step, tr_loss = m.train()
    m.save()  # save the final model

    # do evaluation using the final model
    # m.load("path-to-checkpoint")
Exemplo n.º 41
0
# pylint: disable=C0103
"""sniffing for sockets"""
import socket
import sys
from packets import TCP, UDP, ethernet
from options import Options

PACKET_SIZE = 65535

if __name__ == '__main__':
    opts = Options(sys.platform)
    packets_count = opts.capture_count()
    packets_file = opts.output_file()
    count = 0
    capture = None

    if opts.get_platform() == 'win':
        capture = socket.socket(socket.AF_INET, socket.SOCK_RAW,
                                socket.IPPROTO_IP)
        #reuse address
        capture.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        capture.bind((socket.gethostbyname(socket.gethostname()), 0))

        if opts.is_promiscuous():
            ethernet.set_promiscuous_mode_on(capture)

    elif opts.get_platform() == 'linux':
        capture = socket.socket(socket.AF_INET, socket.SOCK_RAW,
                                socket.htons(0x03))
Exemplo n.º 42
0
"""
Created on Dec 13, 2018
@author: Yuedong Chen
"""

from options import Options
from solvers import create_solver

if __name__ == '__main__':
    opt = Options().parse()

    solver = create_solver(opt)
    solver.run_solver()

    print('[THE END]')
Exemplo n.º 43
0
 def write_error_message(self, message):
     opt = Options()
     # Clear the screen
     self.screen.fill(DrawingTool.color(opt.background_color))
     self.write_message(message, flip=True)
Exemplo n.º 44
0
from mdnet_init import initialize_model
from mdnet_finetune import mdnet_finetune
from lr_multiplier import LearningRateMultiplier
from bbox_reg import BBoxRegressor

parser = argparse.ArgumentParser()
parser.add_argument('-s', '--seq', default='Car1', help='input seq')
parser.add_argument('-r', '--reg', action='store_true')
args = parser.parse_args()
seq = args.seq
regress = args.reg

##############################
# Initialization
##############################
opts = Options()
path = os.path.join(os.getcwd(), 'data', seq)
imgList, gt = get_data(path) # gt: (x, y, box-width, box-height)

nFrames = len(imgList)
img = imread(imgList[0])
if (len(img.shape) != 3):
        img = np.expand_dims(img, -1)
        img = np.concatenate((img, img, img), -1)
imgSize = img.shape

targetLoc = np.array(gt[0]) # initial bounding box 
result = reg_result = np.zeros((nFrames, 4))
result[0] = reg_result[0] = targetLoc
# result is to keep track of predictions without regression
# result will not be plot if the regressor is active
Exemplo n.º 45
0
    def handle_events(self):
        """ Handle any pygame event """
        opt = Options()
        # pygame logic
        for event in pygame.event.get():
            if event.type == QUIT:
                return Event.DONE

            elif event.type == VIDEORESIZE:
                self.screen = pygame.display.set_mode(event.dict['size'],
                                                      RESIZABLE)
                opt.width = event.dict["w"]
                opt.height = event.dict["h"]
                self.__reflow()
                pygame.display.flip()

            elif event.type == MOUSEMOTION:
                if pygame.mouse.get_focused():
                    pos = pygame.mouse.get_pos()
                    self.select_item_on_hover(*pos)

            elif event.type == KEYDOWN:
                if event.key == K_UP and pygame.key.get_mods(
                ) & KMOD_CTRL and opt.read_from_server:
                    opt.read_delay += 1
                    self.update_window_title()
                elif event.key == K_DOWN and pygame.key.get_mods(
                ) & KMOD_CTRL and opt.read_from_server:
                    opt.read_delay = max(0, opt.read_delay - 1)
                    self.update_window_title()
                elif event.key == K_RETURN:
                    self.load_selected_detail_page()
                elif event.key == K_F4 and pygame.key.get_mods() & KMOD_ALT:
                    return Event.DONE
                elif event.key == K_c and pygame.key.get_mods() & KMOD_CTRL:
                    # Debug function to write the state to a json file
                    #with open("../export_state.json", "w") as state_file:
                    #    state_file.write(json.dumps(self.state, cls=TrackerStateEncoder, sort_keys=True))

                    # Write the seed to the clipboard
                    # (from http://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python)
                    r = Tk()
                    r.withdraw()
                    r.clipboard_clear()
                    r.clipboard_append(self.state.seed)
                    r.destroy()

                #self.generate_run_summary() # This is commented out because run summaries are broken with the new "state" model rewrite of the item tracker

            elif event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    self.load_selected_detail_page()
                if event.button == 3:
                    self.save_window_position()
                    import option_picker
                    self.screen.fill(DrawingTool.color(opt.background_color))
                    self.write_message("Editing options...", flip=True)
                    pygame.event.set_blocked(
                        [QUIT, MOUSEBUTTONDOWN, KEYDOWN, MOUSEMOTION])
                    self.optionPicker.run()
                    pygame.event.set_allowed(
                        [QUIT, MOUSEBUTTONDOWN, KEYDOWN, MOUSEMOTION])
                    self.reset_options()
                    self.reset()

                    if self.state is not None:
                        self.__reflow()
                    return Event.OPTIONS_UPDATE

        return None
Exemplo n.º 46
0
 def from_row(cls, row):
     return cls(row.get("guild_id"), row.get("post_channel"), Options(row.get("options")), row.get("prefix"), row.get("_offset"), row.get("special_roles", []), row.get("latest_event_count"), row.get("recent_events", []))
Exemplo n.º 47
0
from options import Options
import os
import re
import subprocess

if __name__ == "__main__":
    # Options
    options = Options().options

    # Check whether negative folder exists
    if not os.path.exists(options.sample_folder):
        print("Creating " + options.sample_folder + " folder")
        os.makedirs(options.sample_folder)
        print("...Done")
        print()

    # Default rngseed value.  This gets incremented after every use
    rngseed = 12345

    print("Looping over all the positive images")
    for image_filename in os.listdir(options.positive_folder):
        # CreateTrainingSamplesFromInfo
        # Create positive samples for all positive images
        subprocess.call([
            r"C:\opencv\build\x64\vc15\bin\opencv_createsamples",
            "-img",
            os.path.join(options.positive_folder, image_filename),
            "-bg",
            "negatives.txt",
            # The positive images are png files, so replacing their filename with txt
            "-info",
Exemplo n.º 48
0
 def load_detail_page(self):
     url = Options().item_details_link
     if not url:
         return
     url = url.replace("$ID", self.item.item_id)
     webbrowser.open(url, autoraise=True)
Exemplo n.º 49
0
 def test_02_getitem(self):
     """Test if getting items with []s works as specified."""
     options = Options("debug", "verbose", log_file="logging.txt", port=80)
     message = "Retrieving an unspecfied option must return False."
     # no need to check specified options, since checked in previous test
     self.assertEqual(options["fsdgjhgd"], False, message)
Exemplo n.º 50
0
 def load_detail_page(self):
     url = Options().item_details_link
     if not url:
         return
     url = url.replace("$ID", self.item.item_id)
     webbrowser.open(url, autoraise=True)
Exemplo n.º 51
0
    import matplotlib.pyplot as plt

    input_space = Space([Real(0., 10., transform="normalize", name="t")])
    parameter_space = Space([Real(0., 1., transform="normalize", name="x")])
    # input_space = Space([Real(0., 0.0001, "uniform", "normalize", name="t")])
    # parameter_space = Space([Real(-1., 1., "uniform", "normalize", name="x")])

    output_space = Space([Real(float('-Inf'), float('Inf'), name="time")])
    constraints = {"cst1": "x >= 0. and x <= 1."}
    # problem = TuningProblem(input_space, parameter_space,output_space, objectives, constraints, models)  # with performance model
    problem = TuningProblem(input_space, parameter_space, output_space,
                            objectives, constraints,
                            None)  # no performance model

    computer = Computer(nodes=1, cores=16, hosts=None)
    options = Options()
    options['model_restarts'] = 1

    options['distributed_memory_parallelism'] = False
    options['shared_memory_parallelism'] = False

    options['objective_evaluation_parallelism'] = False
    options['objective_multisample_threads'] = 1
    options['objective_multisample_processes'] = 1
    options['objective_nprocmax'] = 1

    options['model_processes'] = 1
    # options['model_threads'] = 1
    # options['model_restart_processes'] = 1

    # options['search_multitask_processes'] = 1
Exemplo n.º 52
0
 def get_message_duration(self):
     return Options().message_duration * Options().framerate_limit
Exemplo n.º 53
0
from options import Options

options = Options()
options.add_option('pattern_length', 5, 'Length of pattern to search')
options.add_option('string_length', 10, 'Length of string to search in')
options.add_option('match', True,
                   'Whether to generate a matching or non-matching pattern')

DESCRIPTION = 'Produces a worst-case string and search pattern for the Knuth-Moore-Pratt string matching algorithm.' \
              '\n\n  ' \
              'The worst case for the KMP algorithm is O(n+m), where n is the length of the pattern being searched, and ' \
              'm is the length of the string being searched in.'

DEFAULT_INPUT = 'char'


def run(generator, output):
    if options['match']:
        ret = all_same_match(generator, options['string_length'],
                             options['pattern_length'])
    else:
        ret = no_match(generator, options['string_length'],
                       options['pattern_length'])
    output.output(ret)


def no_match(generator, string_length,
             pattern_length):  # For if you want to not match the pattern
    base = generator.get_min_value()
    pattern = pattern_length * base
    k = string_length // pattern_length
Exemplo n.º 54
0
    def __reflow(self):
        '''
        Regenerate the displayed item list
        '''
        opt = Options()
        size_multiplier = opt.size_multiplier

        # Empty the previous drawn items list
        self.drawn_items[:] = []
        # Build the list of items to display
        items_to_flow = [x for x in self.state.item_list if self.show_item(x)
                         ] if self.state is not None else []
        n_items_to_flow = len(items_to_flow)

        if n_items_to_flow == 0:
            self.next_item = (0, self.text_height + self.text_margin_size)
            return

        # Check for trailing floor and consider we'll have to draw it
        if items_to_flow[-1].floor != self.state.last_floor:
            n_items_to_flow += 1

        # Compute the icon size according to user's multiplier, as well as
        # the minimum size that we want to display (the "footprint")
        icon_size = int(opt.default_spacing * size_multiplier)
        min_icon_footprint = int(opt.min_spacing * size_multiplier)

        # Declare these variables here so that we can reuse it after the loop
        max_col = 0
        available_width = 0

        # Find the biggest possible footprint while displaying every items,
        chosen_icon_footprint = icon_size
        while chosen_icon_footprint >= min_icon_footprint:
            # Compute the maximum number of columns, taking into account the
            # last item's width
            available_width = opt.width - (icon_size - chosen_icon_footprint)
            if opt.enable_mouseover:
                # Boxes have a line width of 2px, so we need to substract them
                available_width -= 2
            max_col = floor(available_width / chosen_icon_footprint)
            row_height = chosen_icon_footprint
            if self.show_floors:
                row_height += self.text_margin_size
            # height also has to take into account the size of the items on the edges, so they never flow off the bottom
            available_height = opt.height - self.text_height - (
                icon_size - chosen_icon_footprint)
            max_row = floor(available_height / row_height)
            # We have our maximum number of columns and rows visible, we can
            # check if everything will fit, or if we reached the minimal size
            if (n_items_to_flow <= max_col * max_row
                    or chosen_icon_footprint == min_icon_footprint):
                break
            chosen_icon_footprint -= 1

        unused_pixels = 0
        # If we fully filled the row, and the number of items per line doesn't
        # match the exact windows width, then we have some pixels left to use
        # to perfectly "stretch" the items
        if n_items_to_flow > max_col or chosen_icon_footprint != icon_size:
            unused_pixels = available_width % chosen_icon_footprint

        # Compute the strech needed per item, and the possible stretch remaining
        # We use max_col - 1 because we want the first item to be left-aligned
        stretch_per_item = 0
        stretch_remaining = 0
        if max_col > 1:
            stretch_per_item = int(unused_pixels / (max_col - 1))
            if stretch_per_item == 0:
                stretch_remaining = unused_pixels
            else:
                stretch_remaining = unused_pixels % stretch_per_item

        # Compute x,y positions for each items
        cur_col = 0
        cur_row = 0
        xpos = 0
        ypos = self.text_height + self.text_margin_size
        for item in items_to_flow:
            # Deal with drawable items
            self.drawn_items.append(DrawableItem(item, xpos, ypos, self))
            cur_col += 1
            if (cur_col % max_col == 0):
                cur_col = 0
                cur_row += 1
                xpos = 0
                ypos += self.text_margin_size + chosen_icon_footprint
            else:
                xpos += chosen_icon_footprint + stretch_per_item
                # If some stretch is remaining, add 1 px per item until we reach
                # the maximum stretch remaining
                if cur_col <= stretch_remaining:
                    xpos += 1

        # Set coordinates for trailing floor, in case it would be needed
        self.next_item = (xpos, ypos)
        self.build_position_index()
Exemplo n.º 55
0
from .deflate import max_deflate_png
from options import Options

options = Options()
options.add_option('width', 225000,
                   'Desired width of uncompressed PNG in pixels')
options.add_option('height', 225000,
                   'Desired height of uncompressed PNG in pixels')

DESCRIPTION = 'Generates a PNG bomb.' \
              '\n\n  ' \
              'The PNG file output expands immensely when loaded into memory by certain applications. ' \
              'We construct a custom PNG file from scratch, inserting a DEFLATE compression bomb, as DEFLATE ' \
              'is the underlying compression used in PNG.'

# NOTE: We looked at using the pypng library for this instead of the custom deflate code
# While the png code is significantly simpler, it also takes significantly longer to run
# because the png library uses zlib for compression, whereas the custom implementation knows
# that the input is all zero bytes and thus can write out the compressed data directly

NO_INPUT = True
DEFAULT_OUTPUT = 'file'
DEFAULT_OUTPUT_OPTIONS = {'final_newline': False, 'format': 'binary'}


def run(output):
    ret = max_deflate_png(options['width'], options['height'])
    output.output([ret])
Exemplo n.º 56
0
 def __init__(self):
     self.options = Options()
     self.utils = Utils()
     self.gspreadWrapper = GspreadWrapper()
Exemplo n.º 57
0
    print('{0} min oracle calls per instance: {1}'.format(prefix, min(calls)))
    print('{0} avg oracle calls per instance: {1:.2f}'.format(
        prefix,
        float(sum(calls)) / len(calls)))
    print('{0} avg number of explanations per instance: {1:.2f}'.format(
        prefix,
        float(sum(exlen)) / len(exlen)))
    print('{0} avg explanation size per instance: {1:.2f}'.format(
        prefix,
        float(sum(xsize)) / len(xsize)))
    print('')


if __name__ == '__main__':
    # parsing command-line options
    options = Options(sys.argv)

    # making output unbuffered
    if sys.version_info.major == 2:
        sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

    # subset-minimal
    enumerate_all(options,
                  xtype='abductive',
                  xnum=-1,
                  smallest=False,
                  usecld=False,
                  usemhs=False,
                  useumcs=False,
                  prefix='mabd')
    # enumerate_all(options, xtype='contrastive', xnum=-1, smallest=False, usecld=False, usemhs=True, useumcs=False, prefix='mcon3')
def main():
    ap = argparse.ArgumentParser()

    ap.add_argument('--arch', required=True, nargs='+', type=int)
    ap.add_argument('--lr', required=False, type=float, default=.01)
    ap.add_argument('--epochs', required=False, type=int, default=100)
    ap.add_argument('--iters', required=True, type=int)
    ap.add_argument('--trials', required=True, type=int)
    ap.add_argument('--env', required=True)
    ap.add_argument('--t', required=True, type=int)
    ap.add_argument('--grads', required=True, type=int)

    ap.add_argument('--weights',
                    required=True,
                    nargs='+',
                    type=float,
                    default=[1.0, .1, .5])
    ap.add_argument('--ufact', required=True, default=4.0, type=float)
    ap.add_argument('--id', required=True, default=4.0, type=int)

    ap.add_argument('--nu', required=True, type=float)
    ap.add_argument('--gamma', required=True, type=float)

    opt = Options()
    args = ap.parse_args()
    opt.load_args(args)
    args = vars(args)

    opt.envname = opt.env
    opt.env = gym.envs.make(opt.envname).env
    opt.sim = gym.envs.make(opt.envname).env
    exp_id = args['id']
    opt.env.my_weights = args['weights']
    opt.env.ufact = args['ufact']
    opt.pi = net.Network([64, 64], .01, 300)
    suffix = '_' + utils.stringify(args['weights']) + '_' + str(args['ufact'])
    weights_path = 'meta/' + 'test' + '/' + opt.envname + '_' + str(
        exp_id) + '_weights' + suffix + '.txt'
    stats_path = 'meta/' + 'test' + '/' + opt.envname + '_' + str(
        exp_id) + '_stats' + suffix + '.txt'
    opt.pi.load_weights(weights_path, stats_path)
    opt.sup = Supervisor(opt.pi)
    opt.misc = Options()
    opt.misc.num_evaluations = 1

    opt.misc.samples = 200
    rec_results = {}
    lnr_results = {}

    plot_dir = utils.generate_plot_dir('initial', 'experts', vars(opt))
    data_dir = utils.generate_data_dir('initial', 'experts', vars(opt))
    if not os.path.exists(plot_dir):
        os.makedirs(plot_dir)
    if not os.path.exists(data_dir):
        os.makedirs(data_dir)
    if not os.path.exists(plot_dir + '/scores'):
        os.makedirs(plot_dir + '/scores')
    if not os.path.exists(plot_dir + '/mags'):
        os.makedirs(plot_dir + '/mags')

    try:
        for t in range(opt.trials):
            start_time = timer.time()
            results = run_trial(opt)

            for key in results['rec'].keys():
                if key in rec_results:
                    rec_results[key].append(results['rec'][key])
                else:
                    rec_results[key] = [results['rec'][key]]

            for key in results['lnr'].keys():
                if key in lnr_results:
                    lnr_results[key].append(results['lnr'][key])
                else:
                    lnr_results[key] = [results['lnr'][key]]

    except KeyboardInterrupt:
        pass

    labels = sorted(list(rec_results.keys()))
    for key in rec_results.keys():
        rec_results[key] = np.array(rec_results[key]) / float(opt.misc.samples)
        lnr_results[key] = np.array(lnr_results[key]) / float(opt.misc.samples)

    rec_means = [
        np.mean(rec_results[key]) for key in sorted(rec_results.keys())
    ]
    rec_sems = [
        scipy.stats.sem(rec_results[key]) for key in sorted(rec_results.keys())
    ]
    lnr_means = [
        np.mean(lnr_results[key]) for key in sorted(lnr_results.keys())
    ]
    lnr_sems = [
        scipy.stats.sem(lnr_results[key]) for key in sorted(lnr_results.keys())
    ]
Exemplo n.º 59
0
def main():
    ## parse flags
    config = Options().parse()
    utils.print_opts(config)

    ## set up folders
    exp_dir = os.path.join(config.exp_dir, config.exp_name)
    model_dir = os.path.join(exp_dir, 'models')
    img_dir = os.path.join(exp_dir, 'images')
    if not os.path.exists(exp_dir):
        os.makedirs(exp_dir)
    if not os.path.exists(model_dir):
        os.makedirs(model_dir)
    if not os.path.exists(img_dir):
        os.makedirs(img_dir)

    if config.use_tbx:
        # remove old tensorboardX logs
        logs = glob.glob(os.path.join(exp_dir, 'events.out.tfevents.*'))
        if len(logs) > 0:
            os.remove(logs[0])
        tbx_writer = SummaryWriter(exp_dir)
    else:
        tbx_writer = None

    ## initialize data loaders/generators & model
    r_loader, z_loader = get_loader(config)
    if config.solver == 'w1':
        model = W1(config, r_loader, z_loader)
    elif config.solver == 'w2':
        model = W2(config, r_loader, z_loader)
    elif config.solver == 'bary_ot':
        model = BaryOT(config, r_loader, z_loader)
    cudnn.benchmark = True
    networks = model.get_networks()
    utils.print_networks(networks)

    ## training
    ## stage 1 (dual stage) of bary_ot
    start_time = time.time()
    if config.solver == 'bary_ot':
        print("Starting: dual stage for %d iters." % config.dual_iters)
        for step in range(config.dual_iters):
            model.train_diter_only(config)
            if ((step + 1) % 100) == 0:
                stats = model.get_stats(config)
                end_time = time.time()
                stats['disp_time'] = (end_time - start_time) / 60.
                start_time = end_time
                utils.print_out(stats, step + 1, config.dual_iters, tbx_writer)
        print("dual stage iterations complete.")

    ## main training loop of w1 / w2 or stage 2 (map stage) of bary-ot
    map_iters = config.map_iters if config.solver == 'bary_ot' else config.train_iters
    if config.solver == 'bary_ot':
        print("Starting: map stage for %d iters." % map_iters)
    else:
        print("Starting training...")
    for step in range(map_iters):
        model.train_iter(config)
        if ((step + 1) % 100) == 0:
            stats = model.get_stats(config)
            end_time = time.time()
            stats['disp_time'] = (end_time - start_time) / 60.
            start_time = end_time
            utils.print_out(stats, step + 1, map_iters, tbx_writer)
        if ((step + 1) % 500) == 0:
            images = model.get_visuals(config)
            utils.visualize_iter(images, img_dir, step + 1, config)
    print("Training complete.")
    networks = model.get_networks()
    utils.save_networks(networks, model_dir)

    ## testing
    root = "./mvg_test"
    file = open(os.path.join(root, "data.pkl"), "rb")
    fixed_z = pickle.load(file)
    file.close()
    fixed_z = utils.to_var(fixed_z)
    fixed_gz = model.g(fixed_z).view(*fixed_z.size())
    utils.visualize_single(fixed_gz, os.path.join(img_dir, 'test.png'), config)
Exemplo n.º 60
0
 def draw_selected_box(self, x, y):
     size_multiplier = int(64 * Options().size_multiplier)
     pygame.draw.rect(self.screen, DrawingTool.color(Options().text_color),
                      (x, y, size_multiplier, size_multiplier), 2)