Commit e3e53b04 authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP

parent bc39dd99
...@@ -141,33 +141,41 @@ SEPARATELY_EXPORTED_PROPERTY_DICT = { ...@@ -141,33 +141,41 @@ SEPARATELY_EXPORTED_PROPERTY_DICT = {
# separate file, with extension specified by 'extension'. # separate file, with extension specified by 'extension'.
# 'extension' must be None for auto-detection. # 'extension' must be None for auto-detection.
# #
# class_name: (extension, unicode_data, property_name), # class_name: (extension, unicode_data, property_name, text),
"Document Component": ("py", 0, "text_content"), "Document Component": ("py", 0, "text_content", True ),
"DTMLDocument": (None, 0, "raw"), "DTMLDocument": (None, 0, "raw", True ),
"DTMLMethod": (None, 0, "raw"), "DTMLMethod": (None, 0, "raw", True ),
"Extension Component": ("py", 0, "text_content"), "Extension Component": ("py", 0, "text_content", True ),
"File": (None, 0, "data"), "File": (None, 0, "data", lambda obj: (obj.content_type.startswith('text/') or
"Image": (None, 0, "data"), obj.content_type in ('application/javascript',
"Interface Component": ("py", 0, "text_content"), 'application/js',
"OOoTemplate": ("oot", 1, "_text"), 'application/json',
"Mixin Component": ("py", 0, "text_content"), 'application/schema+json',
"Module Component": ("py", 0, "text_content"), 'application/x-javascript',
"PDF": ("pdf", 0, "data"), 'application/xml',
"PyData Script": ("py", 0, "_body"), 'application/x-php',
"Python Script": ("py", 0, "_body"), 'image/svg+xml'))),
"Workflow Script": ("py", 0, "_body"), "Image": (None, 0, "data", False),
"PythonScript": ("py", 0, "_body"), "Interface Component": ("py", 0, "text_content", True ),
"Spreadsheet": (None, 0, "data"), "OOoTemplate": ("oot", 1, "_text", True ),
"SQL": ("sql", 0, "src"), "Mixin Component": ("py", 0, "text_content", True ),
"SQL Method": ("sql", 0, "src"), "Module Component": ("py", 0, "text_content", True ),
"Test Component": ("py", 0, "text_content"), "PDF": ("pdf", 0, "data", False),
"Test Page": (None, 0, "text_content"), "PyData Script": ("py", 0, "_body", True ),
"Tool Component": ("py", 0, "text_content"), "Python Script": ("py", 0, "_body", True ),
"Web Illustration": ("svg", 0, "text_content"), "Workflow Script": ("py", 0, "_body", True ),
"Web Page": (None, 0, "text_content"), "PythonScript": ("py", 0, "_body", True ),
"Web Script": (None, 0, "text_content"), "Spreadsheet": (None, 0, "data", False),
"Web Style": (None, 0, "text_content"), "SQL": ("sql", 0, "src", True ),
"ZopePageTemplate": ("zpt", 1, "_text"), "SQL Method": ("sql", 0, "src", True ),
"Test Component": ("py", 0, "text_content", True ),
"Test Page": (None, 0, "text_content", True ),
"Tool Component": ("py", 0, "text_content", True ),
"Web Illustration": ("svg", 0, "text_content", True ),
"Web Page": (None, 0, "text_content", True ),
"Web Script": (None, 0, "text_content", True ),
"Web Style": (None, 0, "text_content", True ),
"ZopePageTemplate": ("zpt", 1, "_text", True ),
} }
def _getCatalog(acquisition_context): def _getCatalog(acquisition_context):
...@@ -823,7 +831,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -823,7 +831,7 @@ class ObjectTemplateItem(BaseTemplateItem):
bta.addObject(obj, name=key, ext='.py') bta.addObject(obj, name=key, ext='.py')
else: else:
try: try:
extension, unicode_data, record_id = \ extension, unicode_data, record_id, _ = \
SEPARATELY_EXPORTED_PROPERTY_DICT[obj.__class__.__name__] SEPARATELY_EXPORTED_PROPERTY_DICT[obj.__class__.__name__]
except KeyError: except KeyError:
pass pass
...@@ -877,10 +885,14 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -877,10 +885,14 @@ class ObjectTemplateItem(BaseTemplateItem):
bta.addObject(xml_data, key + '.catalog_keys', path=path) bta.addObject(xml_data, key + '.catalog_keys', path=path)
def _restoreSeparatelyExportedProperty(self, obj, data): def _restoreSeparatelyExportedProperty(self, obj, data):
unicode_data, property_name = SEPARATELY_EXPORTED_PROPERTY_DICT[ class_name = obj.__class__.__name__
obj.__class__.__name__][1:] unicode_data, property_name, is_text = SEPARATELY_EXPORTED_PROPERTY_DICT[
class_name][1:]
if unicode_data: if unicode_data:
data = data.decode(obj.output_encoding) data = data.decode(obj.output_encoding)
elif ((callable(is_text) and is_text(obj)) or
(not callable(is_text) and is_text)):
data = data.decode('utf-8')
try: try:
setattr(obj, property_name, data) setattr(obj, property_name, data)
except BrokenModified: except BrokenModified:
...@@ -897,6 +909,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -897,6 +909,7 @@ class ObjectTemplateItem(BaseTemplateItem):
obj_key, file_ext = os.path.splitext(file_name) obj_key, file_ext = os.path.splitext(file_name)
# id() for installing several bt5 in the same transaction # id() for installing several bt5 in the same transaction
transactional_variable_obj_key = "%s-%s" % (id(self), obj_key) transactional_variable_obj_key = "%s-%s" % (id(self), obj_key)
obj = None
if file_ext != '.xml': if file_ext != '.xml':
# if the document has not been migrated yet (its class is file and # if the document has not been migrated yet (its class is file and
# it is not in portal_components) use legacy importer # it is not in portal_components) use legacy importer
...@@ -943,6 +956,12 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -943,6 +956,12 @@ class ObjectTemplateItem(BaseTemplateItem):
pass pass
if catalog_method_template_item: if catalog_method_template_item:
self.removeProperties(obj, 0) self.removeProperties(obj, 0)
if obj is not None:
bytes_item_list = [(k, v) for k, v in obj.__dict__.items()
if isinstance(k, bytes) or isinstance(v, bytes) ]
if bytes_item_list:
print("%r: %s" % (getattr(obj, 'content_type', None), file_name))
import pdb; pdb.set_trace()
def build_sub_objects(self, context, id_list, url, **kw): def build_sub_objects(self, context, id_list, url, **kw):
# XXX duplicates code from build # XXX duplicates code from build
...@@ -3954,6 +3973,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem): ...@@ -3954,6 +3973,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
text = file.read() text = file.read()
import pdb; pdb.set_trace()
self._objects[file_name[:-3]] = text self._objects[file_name[:-3]] = text
class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem, class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem,
...@@ -4885,6 +4905,7 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4885,6 +4905,7 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
bta.addObject('\n'.join(xml_data), 'language', path=path) bta.addObject('\n'.join(xml_data), 'language', path=path)
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
import pdb; pdb.set_trace()
name = posixpath.split(file_name)[1] name = posixpath.split(file_name)[1]
if name == 'translation.po': if name == 'translation.po':
text = file.read() text = file.read()
......
...@@ -2524,6 +2524,7 @@ def initialize(self): ...@@ -2524,6 +2524,7 @@ def initialize(self):
time.sleep(5) time.sleep(5)
except: except:
import pdb; pdb.post_mortem() import pdb; pdb.post_mortem()
raise
from Products.TimerService.timerserver.TimerServer import TimerRequest from Products.TimerService.timerserver.TimerServer import TimerRequest
def traverse(*args, **kw): def traverse(*args, **kw):
del TimerRequest.traverse del TimerRequest.traverse
......
...@@ -83,7 +83,7 @@ def unconvert(encoding,S): ...@@ -83,7 +83,7 @@ def unconvert(encoding,S):
if encoding == 'base64': if encoding == 'base64':
return base64.decodestring(S) return base64.decodestring(S)
else: else:
return bytes(eval(b"'" + S.replace(b'\n', b'') + b"'"), 'utf-8') return eval(b"'" + S.replace(b'\n', b'') + b"'").encode('utf-8')
ppml.unconvert = unconvert ppml.unconvert = unconvert
...@@ -328,9 +328,8 @@ class NoBlanks(object): ...@@ -328,9 +328,8 @@ class NoBlanks(object):
""" """
# Ignore element data between elements (eg '<e> <f> </f> </e>')... # Ignore element data between elements (eg '<e> <f> </f> </e>')...
if data.strip(): if data.strip():
if isinstance(data, bytes): if isinstance(data, str):
import pdb; pdb.set_trace() data = data.encode('utf-8')
data = data.encode('raw_unicode_escape')
self.append(data) self.append(data)
# Except for strings and unicode data as whitespaces should be # Except for strings and unicode data as whitespaces should be
...@@ -353,9 +352,8 @@ class NoBlanks(object): ...@@ -353,9 +352,8 @@ class NoBlanks(object):
self.previous_discarded_data = None self.previous_discarded_data = None
self.previous_stack_end = None self.previous_stack_end = None
if isinstance(data, bytes): if isinstance(data, str):
import pdb; pdb.set_trace() data = data.encode('utf-8')
data = data.encode('raw_unicode_escape')
self.append(data) self.append(data)
...@@ -769,8 +767,7 @@ class xmlPickler(NoBlanks, xyap): ...@@ -769,8 +767,7 @@ class xmlPickler(NoBlanks, xyap):
if tag in end: if tag in end:
top = end[tag](self, tag, top) top = end[tag](self, tag, top)
if isinstance(top, str): if isinstance(top, str):
import pdb; pdb.set_trace() top = top.encode('utf-8')
top = top.encode('raw_unicode_escape')
append(top) append(top)
start_handlers={ start_handlers={
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment