Python options.Options() Examples

The following are 29 code examples of options.Options(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module options , or try the search function .
Example #1
Source File: train.py    From ganomaly with MIT License 6 votes vote down vote up
def train():
    """ Training
    """

    ##
    # ARGUMENTS
    opt = Options().parse()
    ##
    # LOAD DATA
    dataloader = load_data(opt)
    ##
    # LOAD MODEL
    model = Ganomaly(opt, dataloader)
    ##
    # TRAIN MODEL
    model.train() 
Example #2
Source File: log_parser.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def parse(self):
        """
        Parse the log file and return a TrackerState object,
        or None if the log file couldn't be found
        """

        self.opt = Options()
        # Attempt to load log_file
        if not self.__load_log_file():
            return None
        self.splitfile = self.content.splitlines()

        # This will become true if we are getting starting items
        self.getting_start_items = False

        # Process log's new output
        for current_line_number, line in enumerate(self.splitfile[self.seek:]):
            self.__parse_line(current_line_number, line)


        self.seek = len(self.splitfile)
        return self.state 
Example #3
Source File: log_parser.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def reset(self):
        """Reset variable specific to the log file/run"""
        # Variables describing the parser state
        self.getting_start_items = False      
        self.reseeding_floor = False
        self.current_room = ""
        self.current_seed = ""
        # Cached contents of log
        self.content = ""
        # Log split into lines
        self.splitfile = []
        self.run_start_line = 0
        self.seek = 0
        self.spawned_coop_baby = 0
        self.log_file_handle = None
        # if they switched between rebirth and afterbirth, the log file we use could change
        self.log_file_path = self.log_finder.find_log_file(self.wdir_prefix)
        self.state.reset(self.current_seed, Options().game_version) 
Example #4
Source File: http.py    From acsploit with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self):
        """Initialize the Http class."""
        self.options = Options()
        self.options.add_option('url', 'http://127.0.0.1:80/', 'Host to connect to')
        self.options.add_option('separator', 'newline', 'Separator between elements',
                                list(self._SEPARATORS.keys()), True)
        self.options.add_option('final_separator', False, 'Whether to end output with an instance of the separator')
        self.options.add_option('number_format', 'decimal', 'Format for numbers', ['decimal', 'hexadecimal', 'octal'])

        # TODO - eventually support PUT, DELETE, HEAD, and OPTIONS, since requests easily handles those
        self.options.add_option('http_method', 'GET', 'Type of HTTP request to make', ['POST', 'GET'])
        self.options.add_option('content_type', '', 'Content-Type header for the HTTP request')
        self.options.add_option('url_param_name', 'param', 'Name of URL arg(s) to use')
        self.options.add_option('spread_params', True, 'Put each output in its own URL arg, as opposed to all in one')
        self.options.add_option('use_body', False, 'Put exploit output in body, not URL args')

        self.options.add_option('print_request', False, 'Print HTTP request')
        self.options.add_option('send_request', True, 'Send HTTP request')

        self.options.add_option('n_requests', 1, 'Total number of times to send the request')
        self.options.add_option('n_parallel', 1, 'Number of requests to send simultaneously')

    # TODO - eventually allow printing out http response? 
Example #5
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def update_window_title(self):
        title = ""
        # The user wants a hard-coded window title
        if Options().custom_title_enabled:
            title = Options().custom_title
        else:
            title = "Rebirth Item Tracker"
            if self.window_title_info.update_notifier:
                title += self.window_title_info.update_notifier

            if self.window_title_info.watching:
                title += ", spectating " + self.window_title_info.watching_player + ". Delay: " + str(Options().read_delay) + ". Updates queued: " + str(self.window_title_info.updates_queued)
            elif self.window_title_info.uploading:
                title += ", uploading to server"

        # Set the title on the actual window
        pygame.display.set_caption(title) 
Example #6
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def build_position_index(self):
        '''
        Builds an array covering the entire visible screen and fills it
        with references to the index items where appropriate so we can show
        select boxes on hover
        '''
        opt = Options()
        w = opt.width
        h = opt.height
        # 2d array of size h, w
        self.item_position_index = [[None for x in xrange(w)] for y in xrange(h)]
        num_displayed_items = 0
        size_multiplier = 64 * opt.size_multiplier
        for item in self.drawn_items:
            if self.show_item(item.item):
                for y in range(int(item.y), int(item.y + size_multiplier)):
                    if y >= h:
                        continue
                    row = self.item_position_index[y]
                    for x in range(int(item.x), int(item.x + size_multiplier)):
                        if x >= w:
                            continue
                        row[x] = num_displayed_items  # Set the row to the index of the item
                num_displayed_items += 1 
Example #7
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def get_image(self, imagename):
        image = self._image_library.get(imagename)
        if image is None:
            path = ""
            need_path = True

            # if we're in antibirth mode, check if there's an antibirth version of the image first
            if self.state and self.state.game_version == "Antibirth":
                path = self.make_path(imagename, True)
                if os.path.isfile(path):
                    need_path = False

            if need_path:
                path = self.make_path(imagename)

            image = pygame.image.load(path)
            size_multiplier = Options().size_multiplier
            scaled_image = image
            # Resize image iff we need to
            if size_multiplier != 1:
                scaled_image = pygame.transform.scale(image, (
                    int(image.get_size()[0] * size_multiplier),
                    int(image.get_size()[1] * size_multiplier)))
            self._image_library[imagename] = scaled_image
        return image 
Example #8
Source File: log_parser.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __trigger_new_run(self, line_number):
        self.log.debug("Starting new run, seed: %s", self.current_seed)
        self.run_start_line = line_number + self.seek
        self.state.reset(self.current_seed, Options().game_version) 
Example #9
Source File: log_parser.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __init__(self, prefix, tracker_version, log_finder):
        self.state = TrackerState("", tracker_version, Options().game_version)
        self.log = logging.getLogger("tracker")
        self.wdir_prefix = prefix
        self.log_finder = log_finder

        self.reset() 
Example #10
Source File: option_picker.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __init__(self):
        self.options = Options()
        self.root = Tk()
        self.root.destroy()
        # Our 'safe' list of fonts that should work in pygame
        self.fonts = ['Andalus', 'Angsana New', 'AngsanaUPC', 'Arial', 'Arial Black', 'Browallia New', 'BrowalliaUPC',
                      'Comic Sans MS', 'Cordia New', 'CordiaUPC', 'Courier New', 'DFKai-SB', 'David', 'DilleniaUPC',
                      'Estrangelo Edessa', 'FrankRuehl', 'Franklin Gothic Medium', 'Gautami', 'Georgia', 'Impact',
                      'IrisUPC', 'JasmineUPC', 'KodchiangUPC', 'Latha', 'LilyUPC', 'Lucida Console', 'MV Boli',
                      'Mangal', 'Microsoft Sans Serif', 'Miriam', 'Miriam Fixed', 'Narkisim', 'Raavi', 'Rod', 'Shruti',
                      'SimHei', 'Simplified Arabic', 'Simplified Arabic Fixed', 'Sylfaen', 'Tahoma', 'Times New Roman',
                      'Traditional Arabic', 'Trebuchet MS', 'Tunga', 'Verdana']
        self.game_versions = ['Rebirth', 'Afterbirth', 'Afterbirth+', 'Antibirth']
        self.network_queue = Queue()

        # Check if the system has the fonts installed, and remove them from the list if it doesn't
        try:
            valid_pygame_fonts = [lower(x.replace(" ", "")) for x in self.fonts]
            system_fonts = pygame.sysfont.get_fonts()
            to_delete = []
            for index, font in enumerate(valid_pygame_fonts):
                if font not in system_fonts:
                    to_delete += [index]
            for index in to_delete[::-1]:
                del self.fonts[index]
        except:
            log_error("There may have been an error detecting system fonts.\n" + traceback.print_exc()) 
Example #11
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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) 
Example #12
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def draw(self, selected=False):
        graphics_id = self.item.info.graphics_id
        if graphics_id is None or len(graphics_id) == 0:
            graphics_id = self.item.item_id

        imagename = ""
        if graphics_id[0] == 'm':
            imagename = "custom/"

        if Options().make_items_glow:
            imagename += "glow/"

        if graphics_id[0] == 'm':
            imagename += graphics_id[1:] + ".png"
        else:
            imagename += DrawingTool.numeric_id_to_image_path(graphics_id)

        image = self.tool.get_image(imagename)
        self.tool.screen.blit(image, (self.x, self.y))
        # If we're a re-rolled item, draw a little d4 near us
        if self.item.was_rerolled:
            self.tool.screen.blit(self.tool.roll_icon, (self.x, self.y))
        # If we're showing blind icons, draw a little blind icon
        if self.show_blind_icon():
            self.tool.screen.blit(
                self.tool.blind_icon,
                (self.x, self.y + Options().size_multiplier * 24)
            )
        # If we're selected, draw a box to highlight us
        if selected:
            self.tool.draw_selected_box(self.x, self.y) 
Example #13
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def show_blind_icon(self):
        """
            We only show the curse of the blind icon if we're showing blind
            icons, the floor it was found on was a blind floor AND
            it's not one of our starting items
        """
        return Options().show_blind_icon and \
               not Options().blck_cndl_mode and \
               self.item.blind and \
               not self.item.starting_item 
Example #14
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def show_item(self, item):
        """
            The highest priority is info.shown, because that way a user can override our logic and stop from seeing an
            item they don't want to see.

            Next is: we always show guppy items. Even if it's a space guppy item and space items are turned off. Because
            guppy is that important. TODO: look into applying this treatment to a few other space items? like nail?

            Finally, check any configurable conditions that might make us not want to show the item, and default to
            showing it if none of those are met.
        """
        opt = Options()
        if not item.info.shown:
            return False
        elif item.info.guppy:
            return True
        elif item.info.health_only and \
                not opt.show_health_ups:
            return False
        elif item.info.space and \
                not opt.show_space_items:
            return False
        elif item.was_rerolled and \
                not opt.show_rerolled_items:
            return False
        return True 
Example #15
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
        ) 
Example #16
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def write_message(self, message, flip=False):
        opt = Options()
        height = draw_text(
            self.screen,
            message,
            self.color(opt.text_color),
            pygame.Rect(2, 2, opt.width - 2, opt.height - 2),
            self.font,
            aa=True,
            wrap=opt.word_wrap
        )
        if flip:
            pygame.display.flip()
        return height 
Example #17
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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) 
Example #18
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_message_duration(self):
        return Options().message_duration * Options().framerate_limit 
Example #19
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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"] 
Example #20
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def tick(self):
        """ Tick the clock. """
        self.clock.tick(int(Options().framerate_limit)) 
Example #21
Source File: view.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def start_pygame(self):
        """ Initialize pygame system stuff and draw empty window """
        if not pygame.display.get_init():
            pygame.display.init()
        if not pygame.font.get_init():
            pygame.font.init()
        pygame.display.set_icon(self.get_image("collectibles_333.png"))
        self.clock = pygame.time.Clock()

        opt = Options()
        # figure out where we should put our window.
        xpos = opt.x_position
        ypos = opt.y_position
        # it can go negative when weird problems happen, so put it in a default location in that case
        if xpos < 0:
            xpos = 100
        if ypos < 0:
            ypos = 100

        os.environ['SDL_VIDEO_WINDOW_POS'] = "%d, %d" % (xpos, ypos)

        if self.screen is None: # If screen is none, we make our own
            self.screen = pygame.display.set_mode((opt.width, opt.height), RESIZABLE)
        self.reset_options()

        if platform.system() == "Windows":
            self.win_info = pygameWindowInfo.PygameWindowInfo()
        del os.environ['SDL_VIDEO_WINDOW_POS']

        self.screen.fill(DrawingTool.color(opt.background_color)) 
Example #22
Source File: log_finder.py    From RebirthItemTracker with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 
Example #23
Source File: strings.py    From acsploit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        """Initialize the String Generator."""
        self.options = Options()
        self.options.add_option('min_length', 1, 'Minimum string length')
        self.options.add_option('max_length', 10, 'Maximum string length')
        self.options.add_option('min_value', 'a', 'Minimum ASCII character to use')
        self.options.add_option('max_value', 'z', 'Maximum ASCII character to use')
        self.options.add_option('restrictions', '', 'String of characters to exclude')
        self.options.add_option('use_whitelist', False, 'If True, only generate characters from the whitelist')
        self.options.add_option('whitelist', '', 'String of characters to generate from if use_whitelist is True')

        self.char_gen = CharGenerator()
        self.prepare() 
Example #24
Source File: floats.py    From acsploit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        """Initialize the Float Generator."""
        self.options = Options()
        self.options.add_option('min_value', 0.0, 'Minimum floating point value allowed')
        self.options.add_option('max_value', 255.0, 'Maximum floating point value allowed')

        self._min = 0.0
        self._max = 255.0 
Example #25
Source File: chars.py    From acsploit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        """Initialize the Chracter generator."""
        self.options = Options()
        self.options.add_option('min_value', 'a', 'Minimum ASCII character to use')
        self.options.add_option('max_value', 'z', 'Maximum ASCII character to use')
        self.options.add_option('restrictions', '', 'String of characters to exclude')
        self.options.add_option('use_whitelist', False, 'If true, only generate characters from the whitelist')
        self.options.add_option('whitelist', '', 'String of characters to generate from if use_whitelist is True')

        # char_set will be a sorted valid set of characters given the constraints set in options
        # char_set must be updated by calling prepare() if options change
        self._char_set = string.ascii_lowercase 
Example #26
Source File: regex.py    From acsploit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        """Initialize the Regex Generator."""
        self.options = Options()
        self.options.add_option('regex', '.*', 'Generated strings will match this regex') 
Example #27
Source File: socket.py    From acsploit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        """Initialize the Socket class."""
        self.options = Options()
        self.options.add_option('host', '127.0.0.1', 'Host to connect to')
        self.options.add_option('port', 80, 'Port to connect to')
        self.options.add_option('ip_version', 'IPv4', 'Version of IP to use', ['IPv4', 'IPv6'])
        self.options.add_option('separator', 'newline', 'Separator between elements',
                                list(self._SEPARATORS.keys()), True)
        self.options.add_option('final_separator', False, 'Whether to end output with an instance of the separator')
        self.options.add_option('await_banner', False, 'Receive a banner message from the server before sending data')
        self.options.add_option('number_format', 'decimal', 'Format for numbers', ['decimal', 'hexadecimal', 'octal']) 
Example #28
Source File: files.py    From acsploit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        """Initialize the File class."""
        self.options = Options()
        self.options.add_option('filename', 'acsploit_output.dat', 'The name of the file to write to')
        # TODO: add more formats
        self.options.add_option('separator', 'newline', 'Separator between elements',
                                list(self._SEPARATORS.keys()), True)
        self.options.add_option('format', 'plaintext', 'The format to write output in', ['plaintext', 'binary', 'sv', 'template'])
        self.options.add_option('final_newline', True, 'Whether to end the file with a newline')
        self.options.add_option('number_format', 'decimal', 'Format for numbers', ['decimal', 'hexadecimal', 'octal'])
        self.options.add_option('template_file', None, 'Template file to use when "format" is "template"')
        self.options.add_option('template_pattern', '<ACSPLOIT>',
                                'Replacement pattern in template file, marks where the payload will be copied')
        self.options.add_option('replace_first_only', False,
                                'Whether to replace only the first occurrence of template_pattern or all occurrences') 
Example #29
Source File: stdout.py    From acsploit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        """Initialize the Stdout class."""
        self.options = Options()
        self.options.add_option('separator', 'newline', 'Separator between elements',
                                list(self._SEPARATORS.keys()), True)
        self.options.add_option('number_format', 'decimal', 'Format for numbers', ['decimal', 'hexadecimal', 'octal'])