Example #1
0
def PoToProperties( pofilename, language, keep_comments, verbose = False ):
	if language is None:
		return

	pp = { }
	po = polib.pofile( pofilename )
	for e in po:
		for ( fname, key ) in e.occurrences:
			if fname not in pp:
				pp[ fname ] = OrderedDict( )
			# Use original text if translation was not finished
			pp[ fname ][ e.comment.strip( ) ] = e.msgstr if e.msgstr != "" else e.msgid
			#pp[ fname ][ e.comment.strip( ) ] = html_unescape( e.msgstr if e.msgstr != "" else e.msgid )

	for ( filename, msgs ) in pp.items( ):
		( root, ext ) = os.path.splitext( filename )
		fname = os.path.join( srcroot, root + "_" + language + ext )
		dname = os.path.dirname( fname )
		if not os.path.exists( dname ):
			os.makedirs( dname )

		master_filename = os.path.join( srcroot, filename )
		if keep_comments and os.path.exists( master_filename ):
			try: # check for file open
				# First, read master file with comments
				fr = open( master_filename, 'rU' )
				mpo = jprops.load_properties( fr, OrderedDict, True )
				fr.close( )

				fw = open( fname, 'w' )
				try: # check for writing contents
					for key in mpo:
						if key[:2] == '#@':
							fw.write( "\n" )
						elif key[:2] == '##':
							jprops.write_comment( fw, mpo[ key ][1:] )
						else:
							if key in msgs:
								jprops.write_property( fw, key, msgs[ key ] )
							else:
								jprops.write_property( fw, key, mpo[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)
Example #2
0
def PoToProperties( pofilename, language, keep_comments, verbose = False ):
	if language is None:
		return

	pp = { }
	po = polib.pofile( pofilename )
	for e in po:
		for ( fname, key ) in e.occurrences:
			if fname not in pp:
				pp[ fname ] = OrderedDict( )
			# Use original text if translation was not finished
			pp[ fname ][ e.comment.strip( ) ] = e.msgstr if e.msgstr != "" else e.msgid
			#pp[ fname ][ e.comment.strip( ) ] = html_unescape( e.msgstr if e.msgstr != "" else e.msgid )

	for ( filename, msgs ) in pp.items( ):
		( root, ext ) = os.path.splitext( filename )
		fname = os.path.join( srcroot, root + "_" + language + ext )
		dname = os.path.dirname( fname )
		if not os.path.exists( dname ):
			os.makedirs( dname )

		master_filename = os.path.join( srcroot, filename )
		if keep_comments and os.path.exists( master_filename ):
			try: # check for file open
				# First, read master file with comments
				fr = open( master_filename, 'rU' )
				mpo = jprops.load_properties( fr, OrderedDict, True )
				fr.close( )

				fw = open( fname, 'w' )
				try: # check for writing contents
					for key in mpo:
						if key[:2] == '#@':
							fw.write( "\n" )
						elif key[:2] == '##':
							jprops.write_comment( fw, mpo[ key ][1:] )
						else:
							if key in msgs:
								jprops.write_property( fw, key, msgs[ key ] )
							else:
								jprops.write_property( fw, key, mpo[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)
 def _send_socket(self, data):
     envLocation = os.environ.get('AUTOMATED_HOME')
     propLocation = os.path.join(envLocation, 'listenerLog0.properties')
     propLocation = os.path.abspath(propLocation)
     lastTestPassed = "true"
     onHold = "false"
     breakPoint = "false"
     lastKeyword = ""
     with open(propLocation) as fp:
         for key, value in jprops.iter_properties(fp):
             if key.startswith('lastTestPassed'):
                 lastTestPassed = value
             if key.startswith('onHold'):
                 onHold = value
             if key.startswith('breakPoint'):
                 breakPoint = value
             if key.startswith('lastKeyword'):
                 lastKeyword = value           
     '''lastTestPassed = "true"
     onHold = "false"
     breakPoint = "false"
     with open(propLocation) as fp:
         for key, value in jprops.iter_properties(fp):
             if key.startswith('lastTestPassed'):
                 lastTestPassed = value
             if key.startswith('onHold'):
                 onHold = value
             if key.startswith('breakPoint'):
                 breakPoint = value
     with open(propLocation, 'w') as fp:
         jprops.write_property(fp, 'lastTestPassed', lastTestPassed)
         jprops.write_property(fp, 'onHold', onHold)
         jprops.write_property(fp, 'breakPoint', 'true')'''
     with open(propLocation, 'w') as fp:   
         jprops.write_property(fp, 'data', data)
         jprops.write_property(fp, 'lastTestPassed', lastTestPassed)
         jprops.write_property(fp, 'onHold', onHold)
         jprops.write_property(fp, 'lastKeyword', lastKeyword)
         jprops.write_property(fp, 'breakPoint', 'true')
Example #4
0
							else:
								jprops.write_property( fw, key, mpo[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)
		else:
			try: # check for file open
				fw = open( fname, 'w' )
				try: # check for writing contents
					for key in msgs:
						jprops.write_property( fw, key, msgs[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)


def ReadProperties( module, language, verbose = False ):
	pot = PotFromProperties( os.path.join( srcroot, module ), language, verbose )

	if pot is None:
		if verbose:
Example #5
0
def test_write_bytes():
    fp = BytesIO()
    jprops.write_property(fp, u'a', u'\u00ff')
    assert fp.getvalue() == b'a=\\u00ff\n'
Example #6
0
def test_write_text():
    fp = StringIO()
    jprops.write_property(fp, u'a', u'\u00ff')
    assert fp.getvalue() == u'a=\u00ff\n'
Example #7
0
def test_write_property_with_comment():
    fp = BytesIO()
    jprops.write_property(fp, jprops.COMMENT, 'foo')
    assert fp.getvalue() == b'#foo\n'
Example #8
0
def test_write_non_string_is_an_error():
    with raises(TypeError):
        jprops.write_property(BytesIO(), b'x', 1)
    with raises(TypeError):
        jprops.write_property(BytesIO(), 1, b'x')
Example #9
0
def test_unicode_in_text_output_not_escaped(key, value, expected):
    b = StringIO()
    jprops.write_property(b, key, value)
    actual = b.getvalue()[:-1]  # strip the trailing newline
    assert actual == expected
Example #10
0
def test_unicode_in_text_output_not_escaped(key, value, expected):
  b = StringIO()
  jprops.write_property(b, key, value)
  actual = b.getvalue()[:-1] # strip the trailing newline
  assert actual == expected
Example #11
0
							else:
								jprops.write_property( fw, key, mpo[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)
		else:
			try: # check for file open
				fw = open( fname, 'w' )
				try: # check for writing contents
					for key in msgs:
						jprops.write_property( fw, key, msgs[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)


def ReadProperties( module, language, verbose = False ):
	pot = PotFromProperties( os.path.join( srcroot, module ), language, verbose )

	if pot is None:
		if verbose:
Example #12
0
def test_write_bytes():
  fp = BytesIO()
  jprops.write_property(fp, u'a', u'\u00ff')
  assert fp.getvalue() == b'a=\\u00ff\n'
Example #13
0
def test_write_text():
  fp = StringIO()
  jprops.write_property(fp, u'a', u'\u00ff')
  assert fp.getvalue() == u'a=\u00ff\n'
Example #14
0
def test_write_property_with_comment():
  fp = BytesIO()
  jprops.write_property(fp, jprops.COMMENT, 'foo')
  assert fp.getvalue() == b'#foo\n'
Example #15
0
def test_write_non_string_is_an_error():
  with raises(TypeError):
    jprops.write_property(BytesIO(), b'x', 1)
  with raises(TypeError):
    jprops.write_property(BytesIO(), 1, b'x')
Example #16
0
def test_escape_unicode_in_bytes_output(key, value, expected):
    b = BytesIO()
    jprops.write_property(b, key, value)
    actual = b.getvalue()[:-1]  # strip the trailing newline
    assert actual == expected
Example #17
0
def test_escape_unicode_in_bytes_output(key, value, expected):
  b = BytesIO()
  jprops.write_property(b, key, value)
  actual = b.getvalue()[:-1] # strip the trailing newline
  assert actual == expected