Commits

Vladimir Kolev  committed dd6ea0b

Made VERSION a variable in the env() class

  • Participants
  • Parent commits 115f354

Comments (0)

Files changed (4)

File lib/SingleService.py

-from enviroment import env 
+from enviroment import env
 import dbus
 import dbus.service
 import dbus.glib
         """
         Method to return the current version of gSharkDown.
         """
-        f = open("%s/VERSION" % env().BASEPATH, 'r')
-        version = f.read()
-        f.close()
-        return version
+        return env().VERSION
 
     @dbus.service.method(dbus_interface = 'org.gsharkdown.Single')
     def get_help(self):

File lib/enviroment.py

     of the app. Is a singleton class an the instance should be accessed
     using the env() function.
     """
-    
+
     def __init__(self):
         # Application name
         self.APP = 'gsharkdown'
-        
+
+        self.VERSION = None
+
         # Data for use Last.fm API
         self.LASTFM_KEY = "51fd71dc8939360b25a1029e556258a4"
         self.LASTFM_SECRET = "cf35dd38f998ca4d3af4adbe59ae23f7"
-        
+
         # URL to check for updates
         self.UPDATE_URL = "http://bitbucket.org/vkolev/gsharkdown/raw/tip/VERSION"
         self.FLATTR_URL = "http://flattr.com/thing/275401/gSharkDown"
-        
+
         ### The following attributes should be initialized on initialize method ###
         # Application base path
         self.BASEPATH = None
-        
+
         # Dependencies information
         self.HAVE_NOTIFY = None
         self.HAVE_PYLAST = None
         self.HAVE_INDICATOR = None
-        
+
         # Directory for i18n files
         self.LOCALE_DIR = None
-        
+
         # The application object (SharkDown instance)
         self._app = None
-        
+
         # The config object
         self._config = None
-    
+
     def app(self):
         return self._app
-    
+
     def set_app(self, app):
         self._app = app
-    
+
     def config(self):
         return self._config
-        
+
     def set_config(self, config):
         self._config = config
-        
+
     def get_config_filename(self):
         """
         Returns the filename for the configuration file
         """
         return "%s/.gsharkdown/gsharkdown.ini" % os.environ.get("HOME")
-        
+
     def get_default_down_path(self):
         """
         Returns the default download path.
         """
         music_dir = glib.get_user_special_dir(glib.USER_DIRECTORY_MUSIC) or os.path.join(os.environ.get("HOME"), "Music")
         return os.path.join(music_dir, "Grooveshark")
-    
+
     def config_defaults(self):
         return {
             'show_stat_icon': 0,
             'file_pattern': "{artist} - {song}",
             'down_path': self.get_default_down_path()
         }
-    
+
     def initialize(self):
         """
         Initialize the enviroment
         gettext.bindtextdomain(self.APP, self.LOCALE_DIR)
         gettext.textdomain(self.APP)
         gettext.install(self.APP, localedir = self.LOCALE_DIR, unicode = True)
-        
+
+        # Initialize the Version number
+        version = open("%s/VERSION" % self.BASEPATH, 'r')
+        self.VERSION = version.readline()
+        version.close()
+
         # Initialize configuration
         config = ConfigObj(self.config_defaults())
         config.filename = self.get_config_filename()
         user_config = ConfigObj(self.get_config_filename())
-        
+
         config.merge(user_config)
-        
+
         if os.path.exists(self.get_config_filename()) == False:
             try:
-                os.mkdir( os.path.dirname(self.get_config_filename()) )
+                os.mkdir(os.path.dirname(self.get_config_filename()))
             except:
                 pass
-            
+
         if os.path.isdir(config['down_path']) == False:
             try:
                 os.makedirs(config['down_path'])
             except:
                 pass
-        
+
         config.write()
         self.set_config(config)
 
 def env():
     global enviroment_singleton
     return enviroment_singleton
-    
+
 def app():
     return env().app()
-    
+
 def config():
     return env().config()

File lib/guihelpers.py

         self.set_default_response(gtk.RESPONSE_OK)
         self.set_title(_("Error"))
         self.connect('response', self.handle_clicked)
-        
+
         self.show_all()
 
     def handle_clicked(self, *args):
         Handler for the default dialog response
         """
         self.lyrics.destroy()
-        
+
 class SongInfoDialog:
     """
     Dialog that shows detailed song information
     """
-    
+
     def __init__(self, song):
         self.dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                       0, gtk.BUTTONS_OK,)
         _year = _("<b>Year:</b> {year}\n").format(year = song.get_year())
         info = _title + _artist + _duration + _album + _year
         self.dialog.set_markup(info)
-        
+
         if song.get_cover_pixbuf() == None:
-            self.set_pixbuf( gtk.gdk.pixbuf_new_from_file("%s/data/loading.png" % env().BASEPATH) )
+            self.set_pixbuf(gtk.gdk.pixbuf_new_from_file("%s/data/loading.png" % env().BASEPATH))
             song.connect("cover-downloaded", self.on_cover_downloaded)
             song.download_cover()
         else:
             self.set_pixbuf(song.get_cover_pixbuf())
-    
+
     def show_all(self):
         self.dialog.show_all()
         self.dialog.run()
         self.dialog.destroy()
-    
+
     def set_pixbuf(self, pixbuf):
         image = gtk.Image()
         image.set_from_pixbuf(pixbuf)
         self.dialog.set_image(image)
         self.dialog.show_all()
-    
+
     def on_cover_downloaded(self, song):
         self.set_pixbuf(song.get_cover_pixbuf())
 
     """
     Show a dialog for configure the preferences
     """
-    
+
     def __init__(self, app):
         self.app = app
-        
+
         builder = gtk.Builder()
         builder.set_translation_domain(env().APP)
         builder.add_from_file('%s/data/preferenes_dialog.ui' % env().BASEPATH)
-        
+
         self.prefs = builder.get_object('window1')
         self.dest = builder.get_object('filechooserbutton1')
         self.dest.set_filename(config()['down_path'])
         self.file_pattern.set_text(config()['file_pattern'])
         self.startup_check = builder.get_object("checkbutton4")
         self.startup_check.set_active(int(config()['startup_update_check']))
-        
+
         if env().HAVE_NOTIFY:
             self.bubble.set_active(int(config()['show_notification']))
         else:
             self.bubble.set_sensitive(False)
-        
+
         self.lastuser = builder.get_object("entry2")
         self.lastuser.set_text(config()['lastuser'])
         self.lastpass = builder.get_object("entry3")
         self.lastpass.set_visibility(False)
         self.lastpass.set_text(config()['lastpass'])
         self.scrobble = builder.get_object("checkbutton3")
-        
+
         if env().HAVE_PYLAST:
             self.scrobble.set_active(int(config()['scrobbling']))
         else:
             self.scrobble.set_sensitive(False)
-        
+
         self.lastuser.set_sensitive(self.scrobble.get_active())
         self.lastpass.set_sensitive(self.scrobble.get_active())
         builder.connect_signals(self)
-    
+
     def show_all(self):
         self.prefs.show_all()
-        
+
     def on_scrobble_toggle(self, widget, data = None):
         self.lastuser.set_sensitive(widget.get_active())
         self.lastpass.set_sensitive(widget.get_active())
-        
+
     def on_save(self, widget, data = None):
         """
         Saves the information from the Preferences dialog in the
         configuration file
         """
         config()['down_path'] = self.dest.get_filename()
-        
+
         if self.quit_without_confirmation.get_active():
             config()['quit_without_confirmation'] = '1'
         else:
             config()['startup_update_check'] = 0
 
         config()['file_pattern'] = self.file_pattern.get_text()
-        config()['speed_limit'] = self.speed.get_value_as_int()  
-        
+        config()['speed_limit'] = self.speed.get_value_as_int()
+
         try:
             if self.scrobble.get_active():
                 lastfm_pass = None
                 lastfm_user = self.lastuser.get_text().strip()
-                
+
                 # Check username
                 if lastfm_user == "":
                     raise Exception(_("The Last.fm username must not be empty."))
-                
+
                 # Check password
                 if config()['lastpass'] == self.lastpass.get_text() and config()["lastuser"] == lastfm_user:
                     lastfm_pass = self.lastpass.get_text()
                     lastfm_pass = pylast.md5(self.lastpass.get_text())
                 else:
                     raise Exception(_("The Last.fm password must not be empty."))
-            
+
                 lastfm = pylast.LastFMNetwork(api_key = env().LASTFM_KEY,
                                               api_secret = env().LASTFM_SECRET,
                                               username = lastfm_user,
-                                              password_hash = lastfm_pass )
+                                              password_hash = lastfm_pass)
                 self.app.lastfm = lastfm
                 self.app.lovebutton.set_sensitive(True)
                 config()['scrobbling'] = 1
                 self.app.lastfm = None
                 config()['scrobbling'] = 0
                 self.app.lovebutton.set_sensitive(False)
-                
+
             config().write()
             self.prefs.destroy()
         except pylast.WSError:
             self.lastuser.select_region(0, -1)
             self.lastuser.grab_focus()
             self.lastpass.set_text("")
-        
+
     def on_cancel(self, widget, data = None):
         """
         Closes the Preferences dialog discarding any changes
         """
         self.prefs.destroy()
-        
+
 class AboutDialog:
     """
     Show the about dialog.
     """
-    
+
     def __init__(self, app):
         builder = gtk.Builder()
         builder.set_translation_domain(env().APP)
         updbtn = builder.get_object('updatbut')
         updbtn.connect("clicked", app.on_check_for_updates)
         about = builder.get_object('aboutdialog1')
+        about.set_version(env().VERSION)
         about.run()
         about.destroy()
-        
+
     def on_flattr_this(self, widget, data = None):
         """
         Opens the flattr page for gSharkDown

File lib/tfuncs.py

                 else:
                     gobject.idle_add(self.app.on_init_thread_failed)
                     p = 0
-                    
+
         gobject.idle_add(self.app.on_init_thread_success)
 
 
         self._stop.wait(1)
         if self.stopped():
             return
-        
+
         try:
             key = groove.getStreamKeyFromSongIDEx(self.song.get_id())
         except Exception, e:
             print e
-            
+
         if self.stopped():
             return
-        
+
         playurls = "http://%s/stream.php?streamKey=%s"
         play_url = playurls % (key["result"]["%s" % self.song.get_id()]["ip"],
                                key["result"]["%s" % self.song.get_id()]["streamKey"])
             gobject.idle_add(self.fill_results, results)
         except Exception, e:
             print e.args
-            
+
     def fill_results(self, results):
         self.app.entry.set_sensitive(True)
         self.app.result.clear()
         threading.Thread.__init__(self)
 
     def run(self):
-        local = open("%s/VERSION" % env().BASEPATH, 'r')
-        localversion = local.read().replace('\n', '')
-        local.close()
-        
+
         remote = urllib2.urlopen(env().UPDATE_URL)
         remoteversion = remote.read().replace('\n', '')
-        
-        if remoteversion > localversion:
+
+        if remoteversion > env().VERSION:
             gobject.idle_add(self.show_update_dialog, True)
         else:
             gobject.idle_add(self.show_update_dialog, False)
-            
+
     def show_update_dialog(self, is_update):
         config()['update_checked'] = 1
         config().write()
-        
+
         secondary_text = _("To update to the latest version ")
         secondary_text += _("you can visit the <a href=\"http://https://bitbucket.org/vkolev/gsharkdown/downloads\"> ")
         secondary_text += _("download site</a>. If you are using the latest version and want to be ")
         secondary_text += _("informed about new versions, just enable the option in the <b>Preferences</b> dialog.")
-        
+
         if is_update:
             main_text = _("<b>New version <span fgcolor=\"red\"><i>%s</i></span> is available</b>")
-            
+
             dialog = guihelpers.UpdateDialog(_('New version'),
                                                  main_text % remoteversion,
                                                  secondary_text)
             dialog.show_all()
         else:
             main_text = _("<b>You are using the latest version!</b>")
-            
+
             dialog = guihelpers.UpdateDialog(_('Latest version'),
                                              main_text,
                                              secondary_text)
     def run(self):
         lyrics = lyrdblib.search(self.song.get_artist(), self.song.get_title())
         gobject.idle_add(self.open_viewer, lyrics)
-        
+
     def open_viewer(self, lyrics):
         self.app.lyrics_button.set_sensitive(True)
         self.app.lyrics_button.set_label(_("Lyrics"))