~flimm/epidermis/icon-theme-bugfix

« back to all changes in this revision

Viewing changes to epidermis/loadrepo.py

  • Committer: David D Lowe
  • Date: 2011-01-04 22:50:19 UTC
  • Revision ID: daviddlowe.flimm@gmail.com-20110104225019-uo31kb54cbxjt5vt
Tidy up code with better comments.
Deleted unused functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
_acceptedEpidermisVersions = ("0.1", "0.4")
24
24
 
25
25
class _CancelException(Exception):
26
 
    """exception that may be raised by the download_hook function"""
 
26
    """Exception that may be raised by the download_hook function"""
27
27
    def __str__(self):
28
28
        return "_CancelException"
29
29
 
30
30
def load_repo(application, forceReload=False):
31
 
    """Loads epidermis repository, downloads and displays it.
32
 
    
33
 
    application: the EpidermisApp object
34
 
    forceReload: whether to ignore application.repoLoaded or not, if forceReload 
35
 
                 is False, load_repo will will only activate if 
36
 
                 application.repoLoaded is False
37
 
    """
38
 
    
 
31
    """Load epidermis repository, download and display it.
 
32
    
 
33
    Keyword arguments:
 
34
    application -- the EpidermisApp object
 
35
    forceReload -- whether to ignore application.repoLoaded or not, if forceReload 
 
36
                   is False, load_repo will will only activate if 
 
37
                   application.repoLoaded is False
 
38
    
 
39
    """    
39
40
    handy.require_main_thread()
40
41
    
41
42
    app = application
66
67
    app.currentDownloadRepoThread.start()
67
68
 
68
69
def clear_repo_cache(app):
69
 
    """deletes all cached information about the repository"""
 
70
    """Delete all cached information about the repository"""
70
71
    if not DEBUG:
71
72
        subprocess.call(["rm", "-r"] + glob(os.path.join(MY_CACHE_HOME, "*")))
72
73
    client = gconf.client_get_default()
77
78
    pass
78
79
            
79
80
class _DownloadRepoThread(threading.Thread):
80
 
    """thread that downloads the file using urllib.urlretrieve"""
 
81
    """Thread that downloads the file using urllib.urlretrieve"""
81
82
    
82
83
    def __init__(self, url, app, wTree):
83
 
        """url: url of repo file to download
84
 
        app:    EpidermisApp
85
 
        wTree:  glade widget tree
 
84
        """Initialiser
 
85
        
 
86
        Keyword arguments:
 
87
        url -- URL of repo file to download
 
88
        app -- EpidermisApp
 
89
        wTree --  glade widget tree
 
90
        
86
91
        """
87
92
        self.url = url
88
93
        self.parent = app
269
274
        downloadDialog.destroy()
270
275
        
271
276
    def _cancel_callback(self, widget):
272
 
        """cancel callback for the cancel button on the download window"""
 
277
        """Cancel callback for the cancel button on the download window"""
273
278
        handy.require_non_main_thread()
274
279
        self.app.cancel = True
275
280
        gobject.idle_add(lambda:self.fetchWin.hide())
279
284
        gobject.idle_add(lambda:self.cancelButton.disconnect(self.handleridCancel))
280
285
        
281
286
    def _download_hook(self, blocksDownloaded, blockSize, size):
282
 
        """download_hook for the download thread that displays progress
283
 
        in the progressbar"""
 
287
        """Download_hook for the download thread that displays progress
 
288
        in the progressbar
 
289
        
 
290
        """
284
291
        handy.require_non_main_thread()
285
292
        downloaded = blocksDownloaded * blockSize
286
293
        frac = blocksDownloaded * blockSize/ size
299
306
            raise(_CancelException())
300
307
 
301
308
    def load_cached_repo(self):
302
 
        """loads repo from cache"""
 
309
        """Load repo from cache"""
303
310
        
304
311
        # read the downloaded preview_summary.xml
305
312
        handy.require_non_main_thread()
402
409
                gobject.idle_add(lambda:self.app.controls.tgFindMore.set_active(True))
403
410
 
404
411
    def prepare_downloaded_repo(self,filename):
405
 
        """this function extracts the downloaded repo archive in the
406
 
        appropriate places in the cache and then runs load_cached_repo()"""
 
412
        """Extract the downloaded repo archive in the appropriate places
 
413
        in the cache and then run load_cached_repo()
 
414
        
 
415
        """
407
416
        sFilename = filename.split("/")[-1:][0]
408
417
        subprocess.call(["rm", os.path.join(MY_CACHE_HOME, "preview_summary.xml")])
409
418
        subprocess.call(["mkdir", "-p", os.path.join(MY_CACHE_HOME)])
426
435
            else:
427
436
                self.load_cached_repo()
428
437
                self.app.checkOnlineRepo = False
429
 
 
430
 
 
431
 
def main():
432
 
    print "This file should not be run"
433
 
    sys.exit(1)
434
 
 
435
 
if __name__ == "__main__":
436
 
    main()