示例#1
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 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]
示例#2
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 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]
示例#3
0
class AccountManager(object):
    accountfile = utils.get_root_filename('accounts')
    accounts = {'default': None, 'accounts': []}
    filename = 'accounts'

    def __init__(self):
        utils.make_dir('')
        self.filename = utils.get_root_filename('accounts')
        self._load()

    def _load(self):
        if utils.file_exists(self.filename):
            with open(self.filename, 'rb') as f:
                self.accounts = cPickle.load(f)

    def _save(self):
        with open(self.filename, 'wb') as f:
            cPickle.dump(self.accounts, f)
            f.write('ok')

    def add_account(self, username, password, api):
        account = {
            'username': username,
            'password': password,
            'api': api,
        }
        self.accounts['accounts'].append(account)
        self._save()

    def delete_account(self, num):
        self.accounts['accounts'].pop(num)
        self._save()

    def get_account(self, num):
        return self.accounts['accounts'][num]

    def get_accounts(self):
        return self.accounts['accounts']

    def get_default(self):
        num = self.accounts['default']
        if num is not None:
            return self.accounts['accounts'][num]
        else:
            return None

    def set_default(self, val):
        self.accounts['default'] = val
        self._save()

    def unset_default(self):
        self.accounts['default'] = None
示例#4
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.userconfigfile = utils.get_filename(userfolder, 'user.json')
     
     self.msg.info(self.name, 'Reading config files...')
     try:
         self.config = utils.parse_config(self.configfile, utils.config_defaults)
         self.userconfig = utils.parse_config(self.userconfigfile, utils.userconfig_defaults)
     except IOError:
         raise utils.EngineFatal("Couldn't open config file.")
示例#5
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.")
示例#6
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.userconfigfile = utils.get_filename(userfolder, 'user.json')

        self.msg.info(self.name, 'Reading config files...')
        try:
            self.config = utils.parse_config(self.configfile,
                                             utils.config_defaults)
            self.userconfig = utils.parse_config(self.userconfigfile,
                                                 utils.userconfig_defaults)
        except IOError:
            raise utils.EngineFatal("Couldn't open config file.")
示例#7
0
 def __init__(self):
     utils.make_dir('')
     self.filename = utils.get_root_filename('accounts.dict')
     self._load()
示例#8
0
 def __init__(self):
     utils.make_dir('')
     self.filename = utils.get_root_filename('accounts.dict')
     self._load()