def migrate_to_1_12(db): """ Convert resources script lib File into PythonScript and Image """ libs = db.resources.objectValues('File') for lib in libs: lib_id = lib.id() lib_data = lib.data content_type = lib.getContentType() if 'image' in content_type: db.resources.manage_delObjects(lib_id) lib_id = manage_addImage(db.resources, lib_id, lib_data) else: error_re = re.compile('^## Errors:$', re.MULTILINE) ps = PythonScript('testing') try: lib_data = asUnicode(lib_data) except UnicodeDecodeError, e: logger.info("Unknown encoding, skipping: %s" % lib_id) continue ps.write(lib_data) if not error_re.search(ps.read()): db.resources.manage_delObjects(lib_id) blank = manage_addPythonScript(db.resources, lib_id) sc = db.resources._getOb(lib_id) sc.write(lib_data) logger.info("Converted to Script: %s" % lib_id) continue
def _write(self, text, compile): ''' Parses the source, storing the body, params, title, bindings, and source in self. If compile is set, compiles the function. ''' ps = PythonScript(self.id) ps.write(text) if compile: ps._makeFunction(1) self._v_f = f = ps._v_f if f is not None: self.func_code = f.func_code self.func_defaults = f.func_defaults else: # There were errors in the compile. # No signature. self.func_code = bad_func_code() self.func_defaults = None self._body = ps._body self._params = ps._params if not self.title: self.title = ps.title self._setupBindings(ps.getBindingAssignments().getAssignedNames()) self._source = ps.read() # Find out what the script sees.
def migrate_to_1_12(db): """ Convert resources script lib File into PythonScript and Image """ libs = db.resources.objectValues('File') for lib in libs: lib_id = lib.id() lib_data = lib.data content_type = lib.getContentType() if 'image' in content_type: db.resources.manage_delObjects(lib_id) lib_id = manage_addImage(db.resources, lib_id, lib_data) else: error_re = re.compile('^## Errors:$', re.MULTILINE) ps = PythonScript('testing') try: lib_data = asUnicode(lib_data) except UnicodeDecodeError, e: logger.info("Unknown encoding, skipping: %s" % lib_id) continue ps.write(lib_data) if not error_re.search(ps.read()): db.resources.manage_delObjects(lib_id) ignored = manage_addPythonScript(db.resources, lib_id) sc = db.resources._getOb(lib_id) sc.write(lib_data) logger.info("Converted to Script: %s" % lib_id) continue
def _write(self, text, compile): ''' Parses the source, storing the body, params, title, bindings, and source in self. If compile is set, compiles the function. ''' ps = PythonScript(self.id) ps.write(text) if compile: ps._makeFunction() self._v_ft = ps._v_ft self.func_code = ps.func_code self.func_defaults = ps.func_defaults self._body = ps._body self._params = ps._params self.title = ps.title self._setupBindings(ps.getBindingAssignments().getAssignedNames()) self._source = ps.read() # Find out what the script sees.
def read(self): ps = PythonScript(self.id) ps._body = self._body ps._params = self._params return ps.read()