def test_copy_file(self): lfs.copy('tests/hello.txt', 'tmp/hello.txt.bak') file = lfs.open('tmp/hello.txt.bak') try: self.assertEqual(file.read(), 'hello world\n') finally: file.close()
def test_copy_folder_to_folder(self): lfs.copy('tests', 'tmp') file = lfs.open('tmp/tests/hello.txt') try: self.assertEqual(file.read(), 'hello world\n') finally: file.close()
def test_move_file(self): lfs.copy('tests/hello.txt', 'tests/hello.txt.bak') lfs.move('tests/hello.txt.bak', 'tests/hello.txt.old') file = lfs.open('tests/hello.txt.old') self.assertEqual(file.read(), 'hello world\n') self.assertEqual(lfs.exists('tests/hello.txt.bak'), False) lfs.remove('tests/hello.txt.old')
# Write the po into the locale.pot try: locale_pot = locale_folder.open('locale.pot', WRITE) except IOError: # The locale.pot file does not exist create and open locale_pot = locale_folder.make_file('locale.pot') else: with locale_pot: locale_pot.write(data) # Update PO files filenames = set([ x for x in locale_folder.get_names() if x[-3:] == '.po' ]) filenames.add('%s.po' % src_language) for language in config.get_value('target_languages'): filenames.add('%s.po' % language) filenames = list(filenames) filenames.sort() print '* Update PO files:' locale_pot_path = locale_folder.get_absolute_path('locale.pot') for filename in filenames: if locale_folder.exists(filename): write(' %s ' % filename) file_path = locale_folder.get_absolute_path(filename) call(['msgmerge', '-U', '-s', file_path, locale_pot_path]) else: print ' %s (new)' % filename lfs.copy(locale_pot_path, filename) print
# Write the po into the locale.pot try: locale_pot = locale_folder.open('locale.pot', WRITE) except IOError: # The locale.pot file does not exist create and open locale_pot = locale_folder.make_file('locale.pot') else: with locale_pot: locale_pot.write(data) # Update PO files filenames = set([x for x in locale_folder.get_names() if x[-3:] == '.po']) filenames.add('%s.po' % src_language) for language in config.get_value('target_languages'): filenames.add('%s.po' % language) filenames = list(filenames) filenames.sort() print '* Update PO files:' locale_pot_path = locale_folder.get_absolute_path('locale.pot') for filename in filenames: if locale_folder.exists(filename): write(' %s ' % filename) file_path = locale_folder.get_absolute_path(filename) call(['msgmerge', '-U', '-s', file_path, locale_pot_path]) else: print ' %s (new)' % filename file_path = locale_folder.get_absolute_path(filename) lfs.copy(locale_pot_path, file_path) print
def update_locale(srx_handler, exclude_folders, no_wrap=False): # Read configuration for languages config = get_config() src_language = config.get_value('source_language', default='en') # Get local folder package_root = config.get_value('package_root') if lfs.exists(package_root): locale_folder_path = Path('{0}/locale'.format(package_root)) else: locale_folder_path = Path('locale/') locale_folder = lfs.open(locale_folder_path) # Initialize message catalog po = POFile() lines = [] for line in open('MANIFEST').readlines(): line = line.strip() exclude_folder = False for x in exclude_folders: if line.startswith(x): exclude_folder = True break if exclude_folder is False: lines.append(line) # Process Python and HTML files write('* Extract text strings') extensions = [ '.py', '.js', '.xhtml.%s' % src_language, '.xml.%s' % src_language, '.html.%s' % src_language] for path in lines: # Filter files for extension in extensions: if path.endswith(extension): break else: continue # Get the units write('.') try: handler = ro_database.get_handler(path) except Exception: print print '*' print '* Error:', path print '*' raise try: units = handler.get_units(srx_handler=srx_handler) units = list(units) except Exception: print print '*' print '* Error:', path print '*' raise relative_path = locale_folder_path.get_pathto(path) for source, context, line in units: po.add_unit(relative_path, source, context, line) print write('* Update PO template ') data = po.to_str() # Write the po into the locale.pot try: locale_pot = locale_folder.open('locale.pot', WRITE) except IOError: # The locale.pot file does not exist create and open locale_pot = locale_folder.make_file('locale.pot') else: with locale_pot: locale_pot.write(data) # Update PO files filenames = set([ x for x in locale_folder.get_names() if x[-3:] == '.po' ]) filenames.add('%s.po' % src_language) for language in config.get_value('target_languages'): filenames.add('%s.po' % language) filenames = list(filenames) filenames.sort() print '* Update PO files:' locale_pot_path = locale_folder.get_absolute_path('locale.pot') for filename in filenames: if locale_folder.exists(filename): write(' %s ' % filename) file_path = locale_folder.get_absolute_path(filename) if no_wrap: call(['msgmerge', '--no-wrap', '-U', '-s', file_path, locale_pot_path]) else: call(['msgmerge', '-U', '-s', file_path, locale_pot_path]) else: print ' %s (new)' % filename file_path = locale_folder.get_absolute_path(filename) lfs.copy(locale_pot_path, file_path) print
def update_locale(srx_handler, exclude_folders, no_wrap=False): # Read configuration for languages config = get_config() src_language = config.get_value('source_language', default='en') # Get local folder package_root = config.get_value('package_root') if lfs.exists(package_root): locale_folder_path = Path('{0}/locale'.format(package_root)) else: locale_folder_path = Path('locale/') locale_folder = lfs.open(locale_folder_path) # Initialize message catalog po = POFile() lines = [] for line in open('MANIFEST').readlines(): line = line.strip() exclude_folder = False for x in exclude_folders: if line.startswith(x): exclude_folder = True break if exclude_folder is False: lines.append(line) # Process Python and HTML files write('* Extract text strings') extensions = [ '.py', '.js', '.xhtml.%s' % src_language, '.xml.%s' % src_language, '.html.%s' % src_language ] for path in lines: # Filter files for extension in extensions: if path.endswith(extension): break else: continue # Get the units write('.') try: handler = ro_database.get_handler(path) except Exception: print print '*' print '* Error:', path print '*' raise try: units = handler.get_units(srx_handler=srx_handler) units = list(units) except Exception: print print '*' print '* Error:', path print '*' raise relative_path = locale_folder_path.get_pathto(path) for source, context, line in units: po.add_unit(relative_path, source, context, line) print write('* Update PO template ') data = po.to_str() # Write the po into the locale.pot try: locale_pot = locale_folder.open('locale.pot', WRITE) except IOError: # The locale.pot file does not exist create and open locale_pot = locale_folder.make_file('locale.pot') else: with locale_pot: locale_pot.write(data) # Update PO files filenames = set([x for x in locale_folder.get_names() if x[-3:] == '.po']) filenames.add('%s.po' % src_language) for language in config.get_value('target_languages'): filenames.add('%s.po' % language) filenames = list(filenames) filenames.sort() print '* Update PO files:' locale_pot_path = locale_folder.get_absolute_path('locale.pot') for filename in filenames: if locale_folder.exists(filename): write(' %s ' % filename) file_path = locale_folder.get_absolute_path(filename) if no_wrap: call([ 'msgmerge', '--no-wrap', '-U', '-s', file_path, locale_pot_path ]) else: call(['msgmerge', '-U', '-s', file_path, locale_pot_path]) else: print ' %s (new)' % filename file_path = locale_folder.get_absolute_path(filename) lfs.copy(locale_pot_path, file_path) print