Commits

Luca Bianconi committed f899655

Added logging and fixed translation process. Translation set up into ./totalopenstation/locale/

Comments (0)

Files changed (3)

 #: build/scripts-2.7/totalopenstation-gui.py:603
 #: scripts/totalopenstation-gui.py:603
 msgid "Connect"
-msgstr ""
+msgstr "Connetti"
 
 #: build/scripts-2.7/totalopenstation-gui.py:628
 #: scripts/totalopenstation-gui.py:628

scripts/totalopenstation-gui.py

 from totalopenstation.output import BUILTIN_OUTPUT_FORMATS
 from totalopenstation.utils.upref import UserPrefs
 
+import logging
+
+home = os.getenv('USERPROFILE') or os.getenv('HOME')
+confdirpath = home + "/.totalopenstation/"
+
+logger = logging.getLogger('totalopenstation')
+hdlr = logging.FileHandler(confdirpath + 'totalopenstation.log')
+formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
+hdlr.setFormatter(formatter)
+logger.addHandler(hdlr)
+logger.setLevel(logging.INFO)
+
 #import totalopenstation.utils.i18n
 #_ = totalopenstation.utils.i18n.language.gettext
 
 #t = gettext.translation('tops', '../locale', fallback=True)
 #_ = t.lgettext
 
-lang_it = gettext.translation('totalopenstation-gui', 'locale', ['it_IT'])
-lang_en = gettext.translation('totalopenstation-gui', 'locale', ['en'])
-lang_en_US = gettext.translation('totalopenstation-gui', 'locale', ['en_US'])
+lang_it = gettext.translation('totalopenstation', confdirpath + 'locale', ['it'])
+lang_en = gettext.translation('totalopenstation', confdirpath + 'locale', ['en'])
+lang_en_US = gettext.translation('totalopenstation', confdirpath + 'locale', ['en_US'])
 
 lang_en.install()
 
 
     # TODO move this function in a separate module together with scanwin32.py
     # and add conditional loading depending on the operating system
+    logger.info('method: scan()')
 
     available = []
     for i in range(256):
 class AboutDialog(tkSimpleDialog.Dialog):
 
     def body(self, master):
+        logger.info('Open About Dialog')
         title = "Total Open Station %s" % totalopenstation.__version__
         message = _("""
 Total Open Station is copyright 2008-2011 Luca Bianconi, Stefano Costa
 class DownloadDialog(tkSimpleDialog.Dialog):
 
     def body(self, master):
+        logger.info('Open Download Dialog')
         title = "Total Open Station download"
         message = _("""
 Press OK when you're ready to download.\n
         tkSimpleDialog.Dialog.__init__(self, parent)
 
     def body(self, master):
+        logger.info('Open Connect Dialog')
+        
         title = _("waiting for data from device")
         message1 = _("Connection initialized with the following parameters:\n")
         params = "%s\n" % self.conn_str
         tkSimpleDialog.Dialog.__init__(self, parent)
 
     def body(self, master):
+        logger.info('Open Process Dialog')
+        
         title = _("Choose output format and destination file")
         question = _("Output format:\n")
         top_frame = Frame(master)
     def validate(self):
         # do nothing if input is empty
         if self.output_format.get() == '' or self.input_format.get() == '':
+            logger.info('Processing validation: false')
             return False
         else:
+            logger.info('Processing validation: true')
             return True
 
     def apply(self):
                 inputclass = getattr(
                     __import__('totalopenstation.formats.' + mod, None, None, [cls]), cls)
             except ImportError, msg:
+                logger.error(('Process Dialog - Import Error %s', msg))
                 showwarning(_('Import error'),
                             _('Error loading the required input module: %s' % msg))
 
                 outputclass = getattr(
                     __import__('totalopenstation.output.' + mod, None, None, [cls]), cls)
             except ImportError, msg:
+                logger.error(('Process Dialog - Output Error %s', msg))
                 showwarning(_('Import error'),
                             _('Error loading the required output module: %s' % msg))
 
         try:
             sd_file = open(sd, 'wb')
         except TypeError:
+            logger.error('Process Dialog - No output file specified')
             showwarning(_("No output file specified"),
                         _("No processing settings entered!\n"))
         else:
             sd_file.write(output.process())
             sd_file.close()
+            
+            logger.info('Process Dialog - Output file written')
 
 
 class ErrorDialog(tkSimpleDialog.Dialog):
 
     def __init__(self, parent, message):
         self.message = message
+        
+        logger.info('Error Dialog - ' + message)
+        
         tkSimpleDialog.Dialog.__init__(self, parent)
 
     def body(self, master):
 
     def __init__(self, parent):
 
+        logger.info('Started Totalopenstation')
+        
         #init user's preferences config file object
         self.upref = UserPrefs()
 
         elif lang == 'en_US':
             lang_en_US.install()
         
+        logger.info('TotalOpenStation - selected lang: ' + lang)
         #print "lang: " + lang
         self.exit_button["text"] = _("Quit")
+        self.connect_button["text"] = _("Connect")
         
         
 
 			the application
 		'''
 	    if askokcancel("Quit","Do you really want to quit application ?"):
-			self.myParent.destroy()	
+			logger.info('TotalOpenStation - Quit ')
+            self.myParent.destroy()	
 
     def exit_action(self, event):
         self.onAppCloseCallback()
                                     ipady=5)
 
     def connect_action(self, event):
-
+        
+        logger.info('TotalOpenStation - Connection to device ')
+            
         chosen_model = self.optionMODEL_value.get()
         chosen_port = self.option1_value.get()
 
                     modelclass = getattr(
                         __import__('totalopenstation.models.' + mod, None, None, [cls]), cls)
                 except ImportError, msg:
+                    
+                    logger.error('TotalOpenStation - Import Error')
                     showwarning(_('Import error'),
                                 _('Error loading the required model module: %s' % msg))
                 if True:#self.options:
                 try:
                     mc.open()
                 except serial.SerialException, detail:
+                    logger.error('TotalOpenStation - Serial Error')
                     e = ErrorDialog(self.myParent, detail)
                 else:
                     st = DownloadDialog(self.myParent)
                         #autosave downloaed data
                         self.autosave_downloaded_data(result)
                         
+                        logger.info('TotalOpenStation - Downloaded data')
                         showinfo(_('Success!'),
                                  _('Download finished!\nYou have %d bytes of data.') % len(result))
     
             sd = home + "/.totalopenstation/" + str(time.localtime()) + '.tops'
             of = open(sd, 'w')
             oc = of.write(data)
+            logger.info('TotalOpenStation - autosaved data at '+ sd)
         except:
             pass
         
             of = open(d, 'r')
             oc = of.read()
             self.replace_text(oc)
+            logger.info('TotalOpenStation - open file '+ d)
         except:
             pass
 
             data = self.text_area.get("1.0", END)
             of = open(sd, 'w')
             oc = of.write(data)
+            
+            logger.info('TotalOpenStation - save file at '+ sd)
         except:
             pass
             
                 if f.endswith('.po'):
                     lang = f[:len(f) - 3]
                     src = os.path.join(path, f)
-                    dest_path = os.path.join('build', 'locale', lang, 'LC_MESSAGES')
-                    dest = os.path.join(dest_path, 'mussorgsky.mo')
+                    home = os.getenv('USERPROFILE') or os.getenv('HOME')
+                    confdirpath = home + "/.totalopenstation/"
+                    dest_path = os.path.join(confdirpath, 'locale', lang, 'LC_MESSAGES')
+                    dest = os.path.join(dest_path, 'totalopenstation.mo')
                     if not os.path.exists(dest_path):
                         os.makedirs(dest_path)
                     if not os.path.exists(dest):
                         print 'Compiling %s' % src
-                        msgfmt.make(src, dest)
+                        totalopenstation.utils.msgfmt.make(src, dest)
                     else:
                         src_mtime = os.stat(src)[8]
                         dest_mtime = os.stat(dest)[8]
                         if src_mtime > dest_mtime:
                             print 'Compiling %s' % src
-                            msgfmt.make(src, dest)
+                            totalopenstation.utils.msgfmt.make(src, dest)
 
 class build(_build):
     sub_commands = _build.sub_commands + [('build_trans', None)]