示例#1
0
    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)]
示例#2
0
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]
示例#3
0
    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))
示例#4
0
 def connect_signal(self, signal, callback):
     try:
         self.signals[signal] = callback
     except KeyError:
         raise utils.EngineFatal("Invalid signal.")
示例#5
0
    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)