コード例 #1
0
ファイル: main.py プロジェクト: ziberna/gnaf
def main():  
    # dirs, files
    user_dir, this_dir, applet_dir = dirs()
    settings_file = user_dir + '/settings.py'
    
    # python paths
    sys.path.insert(0, user_dir)
    sys.path.insert(1, applet_dir)
    
    # gnaf paths
    Gnaf.user_dir = user_dir
    Gnaf.this_dir = this_dir
    Gnaf.applet_dir = applet_dir
    
    # settings
    if not exists(settings_file):
        writeln('No settings file found. Create %s.' % settings_file)
        return False
    try:
        import settings
    except:
        debug()
        writeln('Error in settings file. Check %s.' % settings_file)
        return False
    
    # find applets
    applets = parse_settings(settings, user_dir, applet_dir)
    count = len(applets)
    if count == 0:
        writeln('No applets found. Check %s.' % settings_file)
        return False
    
    # start applets
    for applet in applets:
        if not applet_enabled(applet):
            count -= 1
            continue
        
        for instance in applet['instances']:
            instance(applet['settings'])
    
    if count == 0:
        writeln('No enabled or valid applets found.')
        return False
    
    # start GUI
    logC('Gnaf applets starting (%i total)' % count)
    Gnaf.main()
コード例 #2
0
ファイル: main.py プロジェクト: ziberna/gnaf
def find_applet(user_dir, applet_dir, setting, setting_name):
    applets = []
    
    applet_name = setting['applet']
    class_name = None if not 'class' in setting else setting['class']
    
    user = applet_info(user_dir, 'user')
    installed = applet_info(applet_dir, 'installed')
    
    # search user and applet directories
    for source in [user, installed]:
        path = source['path'] + '/' + applet_name + '/'
        
        if not exists(path + '__init__.py') or not exists(path + 'applet.py'):
            continue
        
        # import module and get its variables
        try:
            module = applet_import(applet_name, source['type'])
        except:
            logLR('%s (%s)' % (setting_name, applet_name), 'IMPORT ERROR')
            if 'debug' not in setting or setting['debug']:
                debug()
            continue
        
        # extract variables
        variables = vars(module)
        # search for a certain variable
        if isstr(class_name) and class_name in variables:
            applets.append(variables[class_name])
        # search for variables as defined in a list
        elif islist(class_name):
            applets.extend(variables[c] for c in class_name if c in variables)
        # except all variables
        else:
            applets.extend(variables[var] for var in variables)
    
    # filter Gnaf classes
    applets = [applet for applet in applets if isgnaf(applet)]
    for applet in applets:
        logLR('%s: class %s (from %s)' % (setting_name, name(applet), applet_name), 'FOUND APPLET')
        applet.instance_name = setting_name
        applet.name = applet_name
    return applets
コード例 #3
0
ファイル: gnaf.py プロジェクト: ziberna/gnaf
 def debug(self):
     if self.settings['debug']:
         debug()