Ejemplo n.º 1
0
class Env:
    ''' Environment variables '''
    _uses_git = False
    _debug = False
    _settings = Settings()
    _loader = Loader()
    _cache = None
    _options = None
    _args = None
    _quiet = False
    _deamonize = False
    _version = 0.5
    ''' Data paths and directories '''
    _app_dir = ""
    _data_dir = ""
    _cache_dir = ""
    _db_path = ""
    _log_path = ""

    @staticmethod
    def doDebug():
        return Env._debug

    @staticmethod
    def get(attr):
        return getattr(Env, '_' + attr)

    @staticmethod
    def set(attr, value):
        return setattr(Env, '_' + attr, value)

    @staticmethod
    def setting(attr, section='core', value=None, default=''):

        # Return setting
        if value == None:
            return Env.get('settings').get(attr,
                                           default=default,
                                           section=section)

        # Set setting
        s = Env.get('settings')
        s.set(section, attr, value)
        return s

    @staticmethod
    def getPermission(type):
        return int(
            Env.get('settings').get('permission_%s' % type, default=0777))
Ejemplo n.º 2
0
class Env(object):

    _appname = 'CouchPotato'

    ''' Environment variables '''
    _app = None
    _encoding = 'UTF-8'
    _debug = False
    _dev = False
    _settings = Settings()
    _loader = Loader()
    _cache = None
    _options = None
    _args = None
    _quiet = False
    _daemonized = False
    _desktop = None
    _engine = None

    ''' Data paths and directories '''
    _app_dir = ""
    _data_dir = ""
    _cache_dir = ""
    _db_path = ""
    _log_path = ""

    @staticmethod
    def doDebug():
        return Env._debug

    @staticmethod
    def get(attr):
        return getattr(Env, '_' + attr)

    @staticmethod
    def all():
        ret = ''
        for attr in ['encoding', 'debug', 'args', 'app_dir', 'data_dir', 'desktop', 'options']:
            ret += '%s=%s ' % (attr, Env.get(attr))

        return ret

    @staticmethod
    def set(attr, value):
        return setattr(Env, '_' + attr, value)

    @staticmethod
    def getSession():
        session = sessionmaker(bind = Env.getEngine())
        return session()

    @staticmethod
    def getEngine():
        existing_engine = Env.get('engine')
        if existing_engine:
            return existing_engine

        engine = create_engine(Env.get('db_path'), echo = False)
        Env.set('engine', engine)

        return engine

    @staticmethod
    def setting(attr, section = 'core', value = None, default = '', type = None):

        s = Env.get('settings')

        # Return setting
        if value is None:
            return s.get(attr, default = default, section = section, type = type)

        # Set setting
        s.addSection(section)
        s.set(section, attr, value)
        s.save()

        return s

    @staticmethod
    def prop(identifier, value = None, default = None):
        s = Env.get('settings')
        if value is None:
            v = s.getProperty(identifier)
            return v if v else default

        s.setProperty(identifier, value)

    @staticmethod
    def getPermission(setting_type):
        perm = Env.get('settings').get('permission_%s' % setting_type, default = '0777')
        if perm[0] == '0':
            return int(perm, 8)
        else:
            return int(perm)

    @staticmethod
    def fireEvent(*args, **kwargs):
        return fireEvent(*args, **kwargs)

    @staticmethod
    def addEvent(*args, **kwargs):
        return addEvent(*args, **kwargs)

    @staticmethod
    def getPid():
        try:
            try:
                parent = os.getppid()
            except:
                parent = None
            return '%d %s' % (os.getpid(), '(%d)' % parent if parent and parent > 1 else '')
        except:
            return 0

    @staticmethod
    def getIdentifier():
        return '%s %s' % (Env.get('appname'), fireEvent('app.version', single = True))
Ejemplo n.º 3
0
class NoCache(BaseCache):
    def get(self, key):
        pass


plug = QualityPlugin()
qualities = plug.qualities

handler = logging.StreamHandler()
log = CPLog(__name__)
log.logger.setLevel('DEBUG')
log.logger.addHandler(handler)

Env.set('cache', NoCache())
Env.set('http_opener', requests.Session())
Env.set('loader', Loader())
Env.set('settings', Settings())


class TestPotatoYGG:
    def setUp(self, conf='/test.cfg'):
        Env.get('settings').setFile(base_path + conf)
        loader = Env.get('loader')
        module = loader.loadModule('ygg')
        assert module is not None
        assert loader.loadSettings(module, 'ygg', save=False)
        return module.autoload()

    def test_loginKO(self):
        ygg = self.setUp('/wrong.cfg')
        assert not ygg.login()