Пример #1
0
 def reload_file(self):
     #Download from the internet and combine with the current list
     last_updated = get_modified_time(APP_LIST_PATH)
     update_frequency = CONFIG['Internet']['UpdateApplications'] * 60
     
     if not CONFIG['Internet']['Enable'] or not update_frequency:
         return
     
     #Only update if requirements are met
     next_update = time.time() - update_frequency
     if not self.applist or not last_updated or last_updated < next_update:
     
         if self.q is not None:
             NOTIFY(APPLIST_UPDATE_START)
             NOTIFY.send(self.q)
             
         if self.applist.update(APP_LIST_URL):
             self.applist.save()
             
             if self.q is not None:
                 NOTIFY(APPLIST_UPDATE_SUCCESS)
         else:
             if self.q is not None:
                 NOTIFY(APPLIST_UPDATE_FAIL)
                 
         NOTIFY.send(self.q)
Пример #2
0
def load_program(program_name=None,
                 _update_version=True,
                 _metadata_only=False):

    paths = _get_paths(program_name)
    new_file = False

    if _metadata_only:
        return {'Modified': get_modified_time(paths['Main'])}

    #Load the main file
    try:
        with open(paths['Main'], 'rb') as f:
            loaded_data = decode_file(f.read())

    #Load backup if file is corrupted
    except zlib.error:
        try:
            with open(paths['Backup'], 'rb') as f:
                loaded_data = decode_file(f.read())

        except (IOError, zlib.error):
            new_file = True

    #Don't load backup if file has been deleted
    except IOError:
        new_file = True

    #Create empty data
    if new_file:
        loaded_data = {}

    return upgrade_version(loaded_data, update_metadata=_update_version)
Пример #3
0
def list_data_files():
    """List the name of every saved profile in the data folder.
    The extension is checked, but removed in the output list.
    """
    all_files = list_directory(DATA_FOLDER)
    if all_files is None:
        return []
    date_modified = {f: get_modified_time(os.path.join(DATA_FOLDER, f)) for f in all_files}
    date_sort = sorted(get_items(date_modified), key=itemgetter(1))
    return [k.replace(DATA_EXTENSION, '') for k, v in date_sort if k.endswith(DATA_EXTENSION)][::-1]
Пример #4
0
def load_data(profile_name=None, _update_version=True, _metadata_only=False, _create_new=True):
    """Read a profile (or create new one) and run it through the update."""
    paths = _get_paths(profile_name)
    new_file = False
    
    if _metadata_only:
        return {'Modified': get_modified_time(paths['Main'])}
    
    #Load the main file
    try:
        with CustomOpen(paths['Main'], 'rb') as f:
            loaded_data = decode_file(f, legacy=f.zip is None)
            
    #Load backup if file is corrupted
    except (zlib.error, ValueError):
        try:
            with CustomOpen(paths['Backup'], 'rb') as f:
                loaded_data = decode_file(f, legacy=f.zip is None)
                
        except (IOError, zlib.error, ValueError):
            new_file = True
            
            #Move corrupt file into a folder instead of just silently delete
            if create_folder(paths['CorruptedFolder']):
                hide_file(paths['CorruptedFolder'])
            rename_file(paths['Main'], '{}.{}'.format(paths['Corrupted'], int(time.time())))
    
    #Don't load backup if file has been deleted
    except IOError:
        new_file = True
    
    #Create empty data
    if new_file:
        if _create_new:
            loaded_data = {}
        else:
            return None
        
    return upgrade_version(loaded_data, update_metadata=_update_version)