def _load(self, account): self.account = account # Create home directory utils.make_dir(utils.to_config_path()) self.configfile = utils.to_config_path('config.json') # Create user directory userfolder = "%s.%s" % (account['username'], account['api']) utils.make_dir(utils.to_data_path(userfolder)) self.msg.info(self.name, 'Trackma v{0} - using account {1}({2}).'.format( utils.VERSION, account['username'], account['api'])) self.msg.info(self.name, 'Reading config files...') try: self.config = utils.parse_config( self.configfile, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") # Expand media directories and ignore those that don't exist if isinstance(self.config['searchdir'], str): # Compatibility: Turn a string of a single directory into a list self.msg.debug(self.name, "Fixing string searchdir to list.") self.config['searchdir'] = [self.config['searchdir']] self.searchdirs = [path for path in utils.expand_paths( self.config['searchdir']) if self._searchdir_exists(path)]
def _load(self, account): self.account = account # Create home directory utils.make_dir('') self.configfile = utils.get_root_filename('config.json') # Create user directory userfolder = "%s.%s" % (account['username'], account['api']) utils.make_dir(userfolder) self.msg.info(self.name, 'Trackma v{0} - using account {1}({2}).'.format( utils.VERSION, account['username'], account['api'])) self.msg.info(self.name, 'Reading config files...') try: self.config = utils.parse_config(self.configfile, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") # Load hook file if os.path.exists(utils.get_root_filename('hook.py')): import sys sys.path[0:0] = [utils.get_root()] try: self.msg.info(self.name, "Importing user hooks (hook.py)...") global hook import hook self.hooks_available = True except ImportError: self.msg.warn(self.name, "Error importing hooks.") del sys.path[0]
def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt): self.config = utils.parse_config(utils.get_root_filename('config.json'), utils.config_defaults) self.host_port = self.config['plex_host']+":"+self.config['plex_port'] self.update_wait = update_wait self.status_log = [None, None] self.token = self._get_plex_token() super().__init__(messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt)
def _load(self, account): self.account = account # Create home directory utils.make_dir(utils.to_config_path()) self.configfile = utils.to_config_path('config.json') # Create user directory userfolder = "%s.%s" % (account['username'], account['api']) utils.make_dir(utils.to_data_path(userfolder)) self.msg.info(self.name, 'Trackma v{0} - using account {1}({2}).'.format( utils.VERSION, account['username'], account['api'])) self.msg.info(self.name, 'Reading config files...') try: self.config = utils.parse_config(self.configfile, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") # Expand media directories and ignore those that don't exist if isinstance(self.config['searchdir'], str): # Compatibility: Turn a string of a single directory into a list self.msg.debug(self.name, "Fixing string searchdir to list.") self.config['searchdir'] = [self.config['searchdir']] self.searchdirs = [path for path in utils.expand_paths(self.config['searchdir']) if self._searchdir_exists(path)]
def __init__(self): """Creates main widgets and creates mainloop""" self.config = utils.parse_config(utils.get_root_filename('ui-curses.json'), utils.curses_defaults) keymap = self.config['keymap'] self.keymap_str = self.get_keymap_str(keymap) self.keymapping = self.map_key_to_func(keymap) palette = [] for k, color in self.config['palette'].items(): palette.append( (k, color[0], color[1]) ) sys.stdout.write("\x1b]0;Trackma-curses "+utils.VERSION+"\x07"); self.header_title = urwid.Text('Trackma-curses ' + utils.VERSION) self.header_api = urwid.Text('API:') self.header_filter = urwid.Text('Filter:') self.header_sort = urwid.Text('Sort:title') self.header_order = urwid.Text('Order:d') self.header = urwid.AttrMap(urwid.Columns([ self.header_title, ('fixed', 23, self.header_filter), ('fixed', 17, self.header_sort), ('fixed', 16, self.header_api)]), 'status') top_pile = [self.header] if self.config['show_help']: top_text = "{help}:Help {sort}:Sort " + \ "{update}:Update {play}:Play " + \ "{status}:Status {score}:Score " + \ "{quit}:Quit" top_text = top_text.format(**self.keymap_str) top_pile.append(urwid.AttrMap(urwid.Text(top_text), 'status')) self.top_pile = urwid.Pile(top_pile) self.statusbar = urwid.AttrMap(urwid.Text('Trackma-curses '+utils.VERSION), 'status') self.listheader = urwid.AttrMap( urwid.Columns([ ('weight', 1, urwid.Text('Title')), ('fixed', 10, urwid.Text('Progress')), ('fixed', 7, urwid.Text('Score')), ]), 'header') self.listwalker = ShowWalker([]) self.listbox = urwid.ListBox(self.listwalker) self.listframe = urwid.Frame(self.listbox, header=self.listheader) self.viewing_info = False self.view = urwid.Frame(self.listframe, header=self.top_pile, footer=self.statusbar) self.mainloop = urwid.MainLoop(self.view, palette, unhandled_input=self.keystroke, screen=urwid.raw_display.Screen()) self.mainloop.set_alarm_in(0, self.do_switch_account) self.mainloop.run()
def __init__(self, debug=False): Gtk.ApplicationWindow.__init__(self) self.init_template() self._debug = debug self._configfile = utils.to_config_path('ui-Gtk.json') self._config = utils.parse_config(self._configfile, utils.gtk_defaults) self._main_view = None self._account = None self._engine = None self._init_widgets() self.present()
def get_config(): configfile = utils.get_root_filename('config.json') try: config = utils.parse_config(configfile, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") plex_host_port = config['plex_host']+":"+config['plex_port'] if config['tracker_type'] == "plex": enabled = True else: enabled = False return [enabled, plex_host_port]
def get_config(): # get configs from file configfile = utils.get_root_filename('config.json') try: config = utils.parse_config(configfile, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") plex_host_port = config['plex_host']+":"+config['plex_port'] if config['tracker_type'] == "plex": enabled = True else: enabled = False return [enabled, plex_host_port]
def __init__(self, app, debug=False): Gtk.ApplicationWindow.__init__(self, application=app) self.init_template() self._debug = debug self._configfile = utils.to_config_path('ui-Gtk.json') self._config = utils.parse_config(self._configfile, utils.gtk_defaults) self.statusicon = None self._main_view = None self._modals = [] self._account = None self._engine = None self.close_thread = None self.hidden = False self._init_widgets()
def _load(self, account): self.account = account # Create home directory utils.make_dir('') self.configfile = utils.get_root_filename('config.json') # Create user directory userfolder = "%s.%s" % (account['username'], account['api']) utils.make_dir(userfolder) self.msg.info( self.name, 'Trackma v{0} - using account {1}({2}).'.format( utils.VERSION, account['username'], account['api'])) self.msg.info(self.name, 'Reading config files...') try: self.config = utils.parse_config(self.configfile, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") # Load hook files hooks_dir = utils.get_root_filename('hooks') if os.path.isdir(hooks_dir): import sys import pkgutil self.msg.info(self.name, "Importing user hooks...") for loader, name, ispkg in pkgutil.iter_modules([hooks_dir]): # List all the hook files in the hooks folder, import them # and call the init() function if they have them # We build the list "hooks available" with the loaded modules # for later calls. try: self.msg.debug(self.name, "Importing hook {}...".format(name)) module = loader.find_module(name).load_module(name) if hasattr(module, 'init'): module.init(self) self.hooks_available.append(module) except ImportError: self.msg.warn(self.name, "Error importing hook {}.".format(name))
def _load(self, account): self.account = account # Create home directory utils.make_dir('') self.configfile = utils.get_root_filename('config.json') # Create user directory userfolder = "%s.%s" % (account['username'], account['api']) utils.make_dir(userfolder) self.msg.info(self.name, 'Trackma v{0} - using account {1}({2}).'.format( utils.VERSION, account['username'], account['api'])) self.msg.info(self.name, 'Reading config files...') try: self.config = utils.parse_config(self.configfile, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") # Load hook files hooks_dir = utils.get_root_filename('hooks') if os.path.isdir(hooks_dir): import sys import pkgutil self.msg.info(self.name, "Importing user hooks...") for loader, name, ispkg in pkgutil.iter_modules([hooks_dir]): # List all the hook files in the hooks folder, import them # and call the init() function if they have them # We build the list "hooks available" with the loaded modules # for later calls. try: self.msg.debug(self.name, "Importing hook {}...".format(name)) module = loader.find_module(name).load_module(name) if hasattr(module, 'init'): module.init(self) self.hooks_available.append(module) except ImportError: self.msg.warn(self.name, "Error importing hook {}.".format(name))
def _load_userconfig(self): self.msg.debug(self.name, "Reading userconfig...") self.userconfig = utils.parse_config(self.userconfig_file, utils.userconfig_defaults)
def __init__(self): """Creates main widgets and creates mainloop""" self.config = utils.parse_config(utils.to_config_path('ui-curses.json'), utils.curses_defaults) keymap = utils.curses_defaults['keymap'] keymap.update(self.config['keymap']) self.keymap_str = self.get_keymap_str(keymap) self.keymapping = self.map_key_to_func(keymap) palette = [] for k, color in self.config['palette'].items(): palette.append( (k, color[0], color[1]) ) # Prepare header sys.stdout.write("\x1b]0;Trackma-curses "+utils.VERSION+"\x07"); self.header_title = urwid.Text('Trackma-curses ' + utils.VERSION) self.header_api = urwid.Text('API:') self.header_filter = urwid.Text('Filter:') self.header_sort = urwid.Text('Sort:title') self.header_order = urwid.Text('Order:d') self.header = urwid.AttrMap(urwid.Columns([ self.header_title, ('fixed', 30, self.header_filter), ('fixed', 17, self.header_sort), ('fixed', 16, self.header_api)]), 'status') top_pile = [self.header] if self.config['show_help']: top_text = "{help}:Help {sort}:Sort " + \ "{update}:Update {play}:Play " + \ "{status}:Status {score}:Score " + \ "{quit}:Quit" top_text = top_text.format(**self.keymap_str) top_pile.append(urwid.AttrMap(urwid.Text(top_text), 'status')) self.top_pile = urwid.Pile(top_pile) # Prepare status bar self.status_text = urwid.Text('Trackma-curses '+utils.VERSION) self.status_queue = urwid.Text('Q:N/A') self.status_tracker = urwid.Text('T:N/A') self.statusbar = urwid.AttrMap(urwid.Columns([ self.status_text, ('fixed', 10, self.status_tracker), ('fixed', 6, self.status_queue), ]), 'status') self.listheader = urwid.AttrMap( urwid.Columns([ ('weight', 1, urwid.Text('Title')), ('fixed', 10, urwid.Text('Progress')), ('fixed', 7, urwid.Text('Score')), ]), 'header') self.listwalker = ShowWalker([]) self.listbox = urwid.ListBox(self.listwalker) self.listframe = urwid.Frame(self.listbox, header=self.listheader) self.viewing_info = False self.view = urwid.Frame(self.listframe, header=self.top_pile, footer=self.statusbar) self.mainloop = urwid.MainLoop(self.view, palette, unhandled_input=self.keystroke, screen=urwid.raw_display.Screen())
def __init__(self): """Creates main widgets and creates mainloop""" palette = [ ('body','', ''), ('focus','standout', ''), ('head','light red', 'black'), ('header','bold', ''), ('status', 'white', 'dark blue'), ('error', 'light red', 'dark blue'), ('window', 'white', 'dark blue'), ('button', 'black', 'light gray'), ('button hilight', 'white', 'dark red'), ('item_airing', 'dark blue', ''), ('item_notaired', 'yellow', ''), ('item_neweps', 'white', 'brown'), ('item_updated', 'white', 'dark green'), ('item_playing', 'white', 'dark blue'), ('info_title', 'light red', ''), ('info_section', 'dark blue', ''), ] keymap = utils.parse_config(utils.get_root_filename('keymap.json'), utils.keymap_defaults) self.keymapping = self.map_key_to_func(keymap) sys.stdout.write("\x1b]0;Trackma-curses "+utils.VERSION+"\x07"); self.header_title = urwid.Text('Trackma-curses ' + utils.VERSION) self.header_api = urwid.Text('API:') self.header_filter = urwid.Text('Filter:') self.header_sort = urwid.Text('Sort:title') self.header_order = urwid.Text('Order:d') self.header = urwid.AttrMap(urwid.Columns([ self.header_title, ('fixed', 23, self.header_filter), ('fixed', 17, self.header_sort), ('fixed', 16, self.header_api)]), 'status') top_text = keymap['help'] + ':Help ' + keymap['sort'] +':Sort ' + \ keymap['update'] + ':Update ' + keymap['play'] + ':Play ' + \ keymap['status'] + ':Status ' + keymap['score'] + ':Score ' + \ keymap['quit'] + ':Quit' self.top_pile = urwid.Pile([self.header, urwid.AttrMap(urwid.Text(top_text), 'status') ]) self.statusbar = urwid.AttrMap(urwid.Text('Trackma-curses '+utils.VERSION), 'status') self.listheader = urwid.AttrMap( urwid.Columns([ ('weight', 1, urwid.Text('Title')), ('fixed', 10, urwid.Text('Progress')), ('fixed', 7, urwid.Text('Score')), ]), 'header') self.listwalker = ShowWalker([]) self.listbox = urwid.ListBox(self.listwalker) self.listframe = urwid.Frame(self.listbox, header=self.listheader) self.viewing_info = False self.view = urwid.Frame(self.listframe, header=self.top_pile, footer=self.statusbar) self.mainloop = urwid.MainLoop(self.view, palette, unhandled_input=self.keystroke, screen=urwid.raw_display.Screen()) self.mainloop.set_alarm_in(0, self.do_switch_account) self.mainloop.run()
manager.set_default(1) else: account_exists = False for num, account in manager.get_accounts(): if account["username"] == username and account["api"] == api: account_exists = True if account["password"] != password: print("Account password mismatch, updating...") manager.edit_account(num, username, password, api) if manager.get_default() != manager.get_account(num): print("Setting account as default") manager.set_default(num) break if not account_exists: print ("Could not find account, adding account...") manager.add_account(username, password, api) manager.set_default(len(manager.get_accounts())) config_path = utils.to_config_path('config.json') try: config = utils.parse_config(config_path, utils.config_defaults) except IOError: raise utils.EngineFatal("Couldn't open config file.") for key, value in config.items(): config[key] = env(key.upper(), cast=type(value), default=value) utils.save_config(config, config_path)