def update_links(self, source, target): Folder.update_links(self, source, target) TagsAware.update_links(self, source, target) base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) # metadata schema = self.class_schema for key, datatype in schema.iteritems(): if issubclass(datatype, PathDataType) is False: continue value = self.get_property(key) if not value: continue ref = get_reference(value) if ref.scheme: continue path, view = get_path_and_view(ref.path) path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new path with the right path new_path = str(new_base.get_pathto(target)) + view self.set_property(key, Path(new_path)) # comments comments = self.metadata.get_property('comment') or [] for comment in comments: # XXX hardcoded, not typed for key in ('attachment',): value = comment.get_parameter(key) if not value: continue ref = get_reference(value) if ref.scheme: continue path, view = get_path_and_view(ref.path) path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new path with the right path new_path = str(new_base.get_pathto(target)) + view comment.set_parameter(key, new_path) self.set_property('comment', comments)
def update_links(self, source, target): # FIXME BaseTheme does not take into account 'child' BaseTheme.update_links(self, source, target) base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) # banner_path site_root = self.get_site_root() available_languages = site_root.get_property("website_languages") for language in available_languages: value = self.get_property("banner_path", language=language) if not value: continue path = old_base.resolve2(value) if path == source: # Hit the old name # Build the new reference with the right path self.set_property("banner_path", new_base.get_pathto(target), language=language) get_context().database.change_resource(self)
class PathComparisonTestCase(TestCase): def setUp(self): self.path_wo_slash = Path('/a/b/c') self.path_w_slash = Path('/a/b/c/') self.wo_to_w = self.path_wo_slash.get_pathto(self.path_w_slash) ######################################################################### # Comparing Path objects def test_with_eq_without_trailing_slash(self): """A path is not the same with a trailing slash.""" self.assertNotEqual(self.path_wo_slash, self.path_w_slash) def test_wo_to_w_eq_path_dot(self): """The path to the same with a trailing slash returns Path('.').""" self.assertEqual(self.wo_to_w, Path('.')) ######################################################################### # Comparing with string conversions. def test_path_wo_slash_eq_string(self): """A path without trailing slash equals its string conversion.""" self.assertEqual(self.path_wo_slash, str(self.path_wo_slash)) def test_path_w_slash_eq_string(self): """A path with trailing slash equals its string conversion.""" self.assertEqual(self.path_w_slash, str(self.path_w_slash)) def test_path_to_similar_eq_string_dot(self): """The path to the same with a trailing slash equals '.'.""" self.assertEqual(self.wo_to_w, '.')
def update_links(self, source, target): base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) handler = self.handler get_value = handler.get_record_value for record in handler.get_records_in_order(): path = get_value(record, 'name') if not path: continue ref = get_reference(path) if ref.scheme: continue # Strip the view path = ref.path name = path.get_name() if name and name[0] == ';': view = '/' + name path = path[:-1] else: view = '' path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new reference with the right path new_ref = deepcopy(ref) new_ref.path = str(new_base.get_pathto(target)) + view handler.update_record(record.id, **{'name': str(new_ref)}) get_context().server.change_resource(self)
def update_links(self, source, target): WebPage.update_links(self, source, target) site_root = self.get_site_root() available_languages = site_root.get_property('website_languages') base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) for lang in available_languages: path = self.get_property('thumbnail', language=lang) if not path: continue ref = get_reference(path) if ref.scheme: continue path, view = get_path_and_view(ref.path) path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new reference with the right path new_ref = deepcopy(ref) new_ref.path = str(new_base.get_pathto(target)) + view self.set_property('thumbnail', str(new_ref), language=lang) get_context().database.change_resource(self)
class PathComparisonTestCase(TestCase): def setUp(self): self.path_wo_slash = Path('/a/b/c') self.path_w_slash = Path('/a/b/c/') self.wo_to_w = self.path_wo_slash.get_pathto(self.path_w_slash) ######################################################################### # Comparing Path objects def test_with_eq_without_trailing_slash(self): """A path is not the same with a trailing slash.""" self.assertNotEqual(self.path_wo_slash, self.path_w_slash) def test_wo_to_w_eq_path_dot(self): """The path to the same with a trailing slash returns Path('.').""" self.assertEqual(self.wo_to_w, Path('.')) ######################################################################### # Comparing with string conversions. def test_path_wo_slash_eq_string(self): """A path without trailing slash equals its string conversion.""" self.assertEqual(self.path_wo_slash, str(self.path_wo_slash)) def test_path_w_slash_eq_string(self): """A path with trailing slash equals its string conversion.""" self.assertEqual(self.path_w_slash, str(self.path_w_slash)) def test_path_to_similar_eq_string_dot(self): """The path to the same with a trailing slash equals '.'.""" self.assertEqual(self.wo_to_w, '.')
def update_links(self, source, target): base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) handler = self.handler get_value = handler.get_record_value for record in handler.get_records_in_order(): path = get_value(record, 'name') if not path: continue ref = get_reference(path) if ref.scheme: continue # Strip the view path = ref.path name = path.get_name() if name and name[0] == ';': view = '/' + name path = path[:-1] else: view = '' path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new reference with the right path new_ref = deepcopy(ref) new_ref.path = str(new_base.get_pathto(target)) + view handler.update_record(record.id, **{'name': str(new_ref)}) get_context().server.change_resource(self)
def update_links(self, source, target): base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) site_root = self.get_site_root() languages = site_root.get_property('website_languages') links = [] for key, datatype in self.get_metadata_schema().items(): multilingual = getattr(datatype, 'multilingual', False) langs = languages if multilingual is True else [None] if issubclass(datatype, XHTMLBody): for lang in langs: events = self.get_property(key, language=lang) if not events: continue events = _change_link(source, target, old_base, new_base, events) events = list(events) self.set_property(key, events, language=lang) elif issubclass(datatype, PathDataType): # Relative path for lang in langs: path = self.get_property(key, language=lang) if path is None: continue path = str(old_base.resolve2(path)) if path == source: # Hit the old name new_path = str(new_base.get_pathto(target)) self.set_property(key, new_path, language=lang) elif issubclass(datatype, AbsolutePathDataTypeEnumerate): # Absolute path for lang in langs: path = self.get_property(key, language=lang) if path is None: continue path = str(path) path = resources_new2old.get(path, path) if path == source: # Hit the old name self.set_property(key, str(target), language=lang) # Tagaware ? if isinstance(self, TagsAware): TagsAware.update_links(self, source, target) # Change resource get_context().database.change_resource(self)
def update_links(self, source, target): super(DiaporamaTable, self).update_links(source, target) # Caution multilingual property base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) site_root = self.get_site_root() available_languages = site_root.get_property('website_languages') handler = self.handler record_properties = handler.record_properties # TODO To improve get_value = handler.get_record_value for record in handler.get_records(): for lang in available_languages: for key in ('img_path', 'img_link'): path = get_value(record, key, lang) if not path: continue ref = get_reference(path) if ref.scheme: continue path, view = get_path_and_view(ref.path) path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new reference with the right path new_ref = deepcopy(ref) new_ref.path = str(new_base.get_pathto(target)) + view datatype = record_properties.get(key, String) new_path = Property(datatype.decode(str(new_ref)), language=lang) handler.update_record(record.id, **{key: new_path}) get_context().database.change_resource(self)
def update_links(self, source, target): source = Path(source) site_root = self.get_site_root() available_languages = site_root.get_property('website_languages') # Tags tags_base = site_root.get_abspath().resolve2('tags') if tags_base.get_prefix(source) == tags_base: tags = list(self.get_property('tags')) source_name = source.get_name() target_name = Path(target).get_name() for tag in tags: if tag == source_name: # Hit index = tags.index(source_name) tags[index] = target_name self.set_property('tags', tags) # Thumbnail base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) for lang in available_languages: path = self.get_property('thumbnail', lang) if not path: continue ref = get_reference(path) if ref.scheme: continue path = old_base.resolve2(path) if path == source: # Hit self.set_property('thumbnail', new_base.get_pathto(target), lang) get_context().database.change_resource(self)
def update_links(self, source, target): WebPage.update_links(self, source, target) base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) path = self.get_property('title_link') if path: ref = get_reference(path) if not ref.scheme: path, view = get_path_and_view(ref.path) path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new reference with the right path new_ref = deepcopy(ref) new_ref.path = str(new_base.get_pathto(target)) + view self.set_property('title_link', str(new_ref)) get_context().database.change_resource(self)
else: continue # Get the units write('.') handler = ro_database.get_handler(path) 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:
def test_pathto_w_slash(self): before = Path('/a/b/') after = Path('/a/b/c') self.assertEqual(before.get_pathto(after), 'c')
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
def test_pathto_w_slash(self): before = Path('/a/b/') after = Path('/a/b/c') self.assertEqual(before.get_pathto(after), 'c')