Package Gnumed :: Package pycommon :: Module gmPrinting
[frames] | no frames]

Source Code for Module Gnumed.pycommon.gmPrinting

  1  """GNUmed printing.""" 
  2  # ======================================================================= 
  3  __version__ = "$Revision: 1.4 $" 
  4  __author__  = "K.Hilbert <Karsten.Hilbert@gmx.net>" 
  5  __license__ = 'GPL (details at http://www.gnu.org)' 
  6   
  7  # ======================================================================= 
  8  import logging, sys, os 
  9   
 10   
 11  if __name__ == '__main__': 
 12          sys.path.insert(0, '../../') 
 13  from Gnumed.pycommon import gmShellAPI 
 14  from Gnumed.pycommon import gmTools 
 15   
 16   
 17  _log = logging.getLogger('gm.printing') 
 18  _log.info(__version__) 
 19   
 20   
 21  known_printjob_types = [ 
 22          u'medication_list', 
 23          u'generic_document' 
 24  ] 
 25   
 26  external_print_APIs = [ 
 27          u'os_startfile', 
 28          u'gm-print_doc' 
 29  ] 
 30   
 31  #======================================================================= 
 32  # internal print API 
 33  #----------------------------------------------------------------------- 
 59  #======================================================================= 
 60  # external print APIs 
 61  #----------------------------------------------------------------------- 
62 -def __print_file_by_os_startfile(filename=None):
63 64 _log.debug('printing [%s]', filename) 65 66 try: 67 os.startfile(filename, 'print') 68 except AttributeError: 69 _log.exception('platform does not support "os.startfile()", cannot print') 70 return False 71 72 return True
73 #-----------------------------------------------------------------------
74 -def __print_file_by_shellscript(filename=None, jobtype=None):
75 76 paths = gmTools.gmPaths() 77 local_script = os.path.join(paths.local_base_dir, '..', 'external-tools', 'gm-print_doc') 78 79 candidates = [u'gm-print_doc', u'gm-print_doc.bat', local_script, u'gm-print_doc.bat'] 80 args = u' %s %s' % (jobtype, filename) 81 82 success = gmShellAPI.run_first_available_in_shell ( 83 binaries = candidates, 84 args = args, 85 blocking = True, 86 run_last_one_anyway = True 87 ) 88 89 if success: 90 return True 91 92 _log.error('print command failed') 93 return False
94 #======================================================================= 95 # main 96 #----------------------------------------------------------------------- 97 if __name__ == '__main__': 98 99 if len(sys.argv) < 2: 100 sys.exit() 101 102 if sys.argv[1] != 'test': 103 sys.exit() 104 105 from Gnumed.pycommon import gmLog2 106 from Gnumed.pycommon import gmI18N 107 gmI18N.activate_locale() 108 gmI18N.install_domain() 109 110
111 - def test_print_file():
112 return print_file(filename = sys.argv[2], jobtype = sys.argv[3])
113 #-------------------------------------------------------------------- 114 115 print test_print_file() 116 117 # ======================================================================= 118