Ejemplo n.º 1
0
Archivo: FSForm.py Proyecto: poses/erp5
    def _readFile(self, reparse):
        f = open(expandpath(self._filepath), 'rb')
        # update the form with the xml data
        try:
            XMLToForm(f.read(), self)
        except:
            # bare except here, but I hope this is ok, as the
            # exception should be reraised
            # (except if the LOG raises another one ... should we be more paranoid here?)
            import zLOG
            zLOG.LOG('Formulator.FSForm',zLOG.ERROR,
                     'error reading form from file '+expandpath(self._filepath))
            raise

        f.close()
Ejemplo n.º 2
0
 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'r')    # not 'rb', as this is a text file!
     try:
         data = file.read()
     finally:
         file.close()
     if reparse:
         self.write(data)
Ejemplo n.º 3
0
 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'r')  # not 'rb', as this is a text file!
     try:
         data = file.read()
     finally:
         file.close()
     if reparse:
         self.write(data)
Ejemplo n.º 4
0
def FSZSQLMethod_readFile(self, reparse):
    fp = expandpath(self._filepath)
    file = open(fp, 'r')    # not 'rb', as this is a text file!
    try:
        data = file.read()
    finally: file.close()

    RESPONSE = {}
    RESPONSE['BODY'] = data

    self.PUT(RESPONSE,None)
Ejemplo n.º 5
0
def FSZSQLMethod_readFile(self, reparse):
    fp = expandpath(self._filepath)
    file = open(fp, 'r')  # not 'rb', as this is a text file!
    try:
        data = file.read()
    finally:
        file.close()

    RESPONSE = {}
    RESPONSE['BODY'] = data

    self.PUT(RESPONSE, None)
Ejemplo n.º 6
0
        def getImageFP(self, name):
            """Retrieves an image filepath from the ZODB file system
            """
            location = self.context.aq_parent
            try:
                # try to get it from ZODB
                img_pointer = getattr(location, name)
                fp = expandpath(img_pointer._filepath)
            except AttributeError:
                # not found !
                return None

            return (fp, img_pointer.width, img_pointer.height)
Ejemplo n.º 7
0
        def getImageFP(self, name) :
            """Retrieves an image filepath from the ZODB file system
            """
            location = self.context.aq_parent
            try :
                # try to get it from ZODB
                img_pointer = getattr(location, name)
                fp = expandpath(img_pointer._filepath)
            except AttributeError :
                # not found !
                return None

            return (fp, img_pointer.width, img_pointer.height)
Ejemplo n.º 8
0
    def _initSite( self, selections=None, fsdvs=None ):

        if selections is None:
            selections = {}

        if fsdvs is None:
            fsdvs = []

        self.root.site = DummySite()

        for id, fsdv in fsdvs:
            self._registerDirectoryView( expandpath(fsdv._dirpath) )

        self.root.site.portal_skins = DummySkinsTool( selections, fsdvs )

        return self.root.site
Ejemplo n.º 9
0
    def _initSite(self, selections=None, fsdvs=None):

        if selections is None:
            selections = {}

        if fsdvs is None:
            fsdvs = []

        self.root.site = DummySite()

        for id, fsdv in fsdvs:
            self._registerDirectoryView(expandpath(fsdv._dirpath))

        self.root.site.portal_skins = DummySkinsTool(selections, fsdvs)

        return self.root.site
Ejemplo n.º 10
0
        def getImageFromFS(self, name, width=None, height=None):
            """Retrieves an Image from the ZODB file system
            """
            location = self.context.aq_parent
            try:
                # try to get it from ZODB
                img_pointer = getattr(location, name)
                fp = expandpath(img_pointer._filepath)
                if not width:
                    width = img_pointer.width
                if not height:
                    height = img_pointer.height
                p_img = platypus.Image(fp, width=width / 2, height=height / 2)

                return (p_img)

            except AttributeError:
                # not found !
                return None
Ejemplo n.º 11
0
        def getImageFromFS(self, name, width = None, height = None) :
            """Retrieves an Image from the ZODB file system
            """
            location = self.context.aq_parent
            try :
                # try to get it from ZODB
                img_pointer = getattr(location, name)
                fp = expandpath(img_pointer._filepath)
                if not width:
                    width = img_pointer.width
                if not height:
                    height = img_pointer.height
                p_img = platypus.Image(fp, width = width / 2, height = height / 2)

                return (p_img)

            except AttributeError :
                # not found !
                return None
Ejemplo n.º 12
0
def fixSkinNames(self, REQUEST=None, file=None, dry_run=0):
  """
    Fix bad skin names.

    This method does:

      - Check all the contents of all skins.

      - Check immediate_view, constructor_path and actions in all portal types.

      - Check skins of all business templates.

      - Check actbox_url in transitions and worklists and scripts of all workflows.

      - Rename skins.
  """
  if REQUEST is None:
    REQUEST = get_request()

  if file is None:
    msg = 'You must put a CSV file inside the data directory, and specify %s/ERP5Site_fixSkinNames?file=NAME \n\n' % self.absolute_url()
    msg += 'The template of a CSV file is available via %s/ERP5Site_checkSkinNames?csv=1 \n\n' % self.absolute_url()
    msg += 'This does not modify anything by default. If you really want to fix skin names, specify %s/ERP5Site_fixSkinNames?file=NAME&dry_run=0 \n\n' % self.absolute_url()
    return msg

  file = os.path.join(data_dir, file)
  file = open(file, 'r')
  class NamingInformation: pass
  info_list = []
  try:
    reader = csv.reader(file)
    for row in reader:
      folder, name, new_name, meta_type = row[:4]
      if len(row) > 4 and len(row[4]) > 0:
        removed = 1
        new_name = row[4]
      else:
        removed = 0
      if meta_type == 'Meta Type': continue
      if name == new_name: continue
      # Check the existence of the skin and the meta type. Paranoid?
      #if self.portal_skins[folder][name].meta_type != meta_type:
      #  raise RuntimeError, '%s/%s has a different meta type' % (folder, name)
      info = NamingInformation()
      info.meta_type = meta_type
      info.folder = folder
      info.name = name
      info.new_name = new_name
      info.regexp = re.compile('\\b' + re.escape(name) + '\\b') # This is used to search the name
      info.removed = removed
      info_list.append(info)
  finally:
    file.close()

  # Now we have information enough. Check the skins.
  msg = ''
  path_list = getSkinPathList(self)
  for path in path_list:
    skin = self.portal_skins.restrictedTraverse(path)
    try:
      text = skin.manage_FTPget()
    except:
      type, value, traceback = sys.exc_info()
      line = 'WARNING: the skin %s could not be retrieved because of the exception %s: %s\n' % (path, str(type), str(value))
      LOG('fixSkinNames', 0, line)
      msg += '%s\n' % line
    else:
      name_list = []
      for info in info_list:
        if info.regexp.search(text) is not None:
          text = info.regexp.sub(info.new_name, text)
          name_list.append(info.name)
      if len(name_list) > 0:
        line = '%s is modified for %s' % ('portal_skins/' + path, ', '.join(name_list))
        LOG('fixSkinNames', 0, line)
        msg += '%s\n' % line
        if not dry_run:
          if skin.meta_type in fs_skin_spec:
            f = open(expandpath(skin.getObjectFSPath()), 'w')
            try:
              f.write(text)
            finally:
              f.close()
          else:
            REQUEST['BODY'] = text
            skin.manage_FTPput(REQUEST, REQUEST.RESPONSE)

  # Check the portal types.
  for t in self.portal_types.objectValues():
    # Initial view name.
    text = t.immediate_view
    for info in info_list:
      if info.name == text:
        line = 'Initial view name of %s is modified for %s' % ('portal_types/' + t.id, text)
        LOG('fixSkinNames', 0, line)
        msg += '%s\n' % line
        if not dry_run:
          t.immediate_view = info.new_name
        break
    # Constructor path.
    text = getattr(t, 'constructor_path', None)
    if text is not None:
      for info in info_list:
        if info.name == text:
          line = 'Constructor path of %s is modified for %s' % ('portal_types/' + t.id, text)
          LOG('fixSkinNames', 0, line)
          msg += '%s\n' % line
          if not dry_run:
            t.constructor_path = info.new_name
          break
    # Actions.
    for action in t.listActions():
      text = action.action.text
      for info in info_list:
        if info.regexp.search(text) is not None:
          text = info.regexp.sub(info.new_name, text)
          line = 'Action %s of %s is modified for %s' % (action.getId(), 'portal_types/' + t.id, info.name)
          LOG('fixSkinNames', 0, line)
          msg += '%s\n' % line
          if not dry_run:
            action.action.text = text
          break

  # Check the portal templates.
  template_tool = getattr(self, 'portal_templates', None)
  # Check the existence of template tool, because an older version of ERP5 does not have it.
  if template_tool is not None:
    for template in template_tool.contentValues(filter={'portal_type':'Business Template'}):
      # Skins.
      skin_id_list = []
      name_list = []
      for skin_id in template.getTemplateSkinIdList():
        for info in info_list:
          if info.name == skin_id:
            name_list.append(skin_id)
            skin_id = info.new_name
            break
        skin_id_list.append(skin_id)
      if len(name_list) > 0:
        line = 'Skins of %s is modified for %s' % ('portal_templates/' + template.getId(), ', '.join(name_list))
        LOG('fixSkinNames', 0, line)
        msg += '%s\n' % line
        if not dry_run:
          template.setTemplateSkinIdList(skin_id_list)
      # Paths.
      path_list = []
      name_list = []
      for path in template.getTemplatePathList():
        for info in info_list:
          if info.regexp.search(path):
            name_list.append(skin_id)
            path = info.regexp.sub(info.new_name, path)
            break
        path_list.append(path)
      if len(name_list) > 0:
        line = 'Paths of %s is modified for %s' % ('portal_templates/' + template.getId(), ', '.join(name_list))
        LOG('fixSkinNames', 0, line)
        msg += '%s\n' % line
        if not dry_run:
          template.setTemplatePathList(path_list)

  # Workflows.
  for wf in self.portal_workflow.objectValues():
    # Transitions.
    for id in wf.transitions.objectIds():
      transition = wf.transitions._getOb(id)
      text = transition.actbox_url
      for info in info_list:
        if info.regexp.search(text) is not None:
          text = info.regexp.sub(info.new_name, text)
          line = 'Transition %s of %s is modified for %s' % (id, 'portal_workflow/' + wf.id, info.name)
          LOG('fixSkinNames', 0, line)
          msg += '%s\n' % line
          if not dry_run:
            transition.actbox_url = text
          break
    # Worklists.
    for id in wf.worklists.objectIds():
      worklist = wf.worklists._getOb(id)
      text = worklist.actbox_url
      for info in info_list:
        if info.regexp.search(text) is not None:
          text = info.regexp.sub(info.new_name, text)
          line = 'Worklist %s of %s is modified for %s' % (id, 'portal_workflow/' + wf.id, info.name)
          LOG('fixSkinNames', 0, line)
          msg += '%s\n' % line
          if not dry_run:
            worklist.actbox_url = text
          break
    # Scripts.
    for id in wf.scripts.objectIds():
      script = wf.scripts._getOb(id)
      text = script.manage_FTPget()
      name_list = []
      for info in info_list:
        if info.regexp.search(text) is not None:
          text = info.regexp.sub(info.new_name, text)
          name_list.append(info.name)
      if len(name_list) > 0:
        line = 'Script %s of %s is modified for %s' % (id, 'portal_workflow/' + wf.id, ', '.join(name_list))
        LOG('fixSkinNames', 0, line)
        msg += '%s\n' % line
        if not dry_run:
          REQUEST['BODY'] = text
          script.manage_FTPput(REQUEST, REQUEST.RESPONSE)

  # Rename the skins.
  if not dry_run:
    for info in info_list:
      try:
        if info.meta_type in fs_skin_spec:
          skin = self.portal_skins[info.folder][info.name]
          old_path = expandpath(skin.getObjectFSPath())
          new_path = info.regexp.sub(info.new_name, old_path)
          if info.removed:
            os.remove(old_path)
          else:
            os.rename(old_path, new_path)
        else:
          folder = self.portal_skins[info.folder]
          if info.removed:
            folder.manage_delObjects([info.name])
          else:
            folder.manage_renameObjects([info.name], [info.new_name])
      except:
        type, value, traceback = sys.exc_info()
        if info.removed:
          line = 'WARNING: the skin %s could not be removed because of the exception %s: %s\n' % (info.name, str(type), str(value))
          LOG('fixSkinNames', 0, line)
          msg += '%s\n' % line
        else:
          line = 'WARNING: the skin %s could not be renamed to %s because of the exception %s: %s\n' % (info.name, info.new_name, str(type), str(value))
          LOG('fixSkinNames', 0, line)
          msg += '%s\n' % line

  return msg
Ejemplo n.º 13
0
def fixSkinNames(self, REQUEST=None, file=None, dry_run=0):
    """
    Fix bad skin names.

    This method does:

      - Check all the contents of all skins.

      - Check immediate_view, constructor_path and actions in all portal types.

      - Check skins of all business templates.

      - Check actbox_url in transitions and worklists and scripts of all workflows.

      - Rename skins.
  """
    if REQUEST is None:
        REQUEST = get_request()

    if file is None:
        msg = 'You must put a CSV file inside the data directory, and specify %s/ERP5Site_fixSkinNames?file=NAME \n\n' % self.absolute_url(
        )
        msg += 'The template of a CSV file is available via %s/ERP5Site_checkSkinNames?csv=1 \n\n' % self.absolute_url(
        )
        msg += 'This does not modify anything by default. If you really want to fix skin names, specify %s/ERP5Site_fixSkinNames?file=NAME&dry_run=0 \n\n' % self.absolute_url(
        )
        return msg

    with open(os.path.join(data_dir, file)) as file:

        class NamingInformation:
            pass

        info_list = []
        reader = csv.reader(file)
        for row in reader:
            folder, name, new_name, meta_type = row[:4]
            if len(row) > 4 and len(row[4]) > 0:
                removed = 1
                new_name = row[4]
            else:
                removed = 0
            if meta_type == 'Meta Type': continue
            if name == new_name: continue
            # Check the existence of the skin and the meta type. Paranoid?
            #if self.portal_skins[folder][name].meta_type != meta_type:
            #  raise RuntimeError, '%s/%s has a different meta type' % (folder, name)
            info = NamingInformation()
            info.meta_type = meta_type
            info.folder = folder
            info.name = name
            info.new_name = new_name
            info.regexp = re.compile('\\b' + re.escape(name) +
                                     '\\b')  # This is used to search the name
            info.removed = removed
            info_list.append(info)

    # Now we have information enough. Check the skins.
    msg = ''
    path_list = getSkinPathList(self)
    for path in path_list:
        skin = self.portal_skins.restrictedTraverse(path)
        try:
            text = skin.manage_FTPget()
        except:
            type, value, traceback = sys.exc_info()
            line = 'WARNING: the skin %s could not be retrieved because of the exception %s: %s\n' % (
                path, str(type), str(value))
            LOG('fixSkinNames', 0, line)
            msg += '%s\n' % line
        else:
            name_list = []
            for info in info_list:
                if info.regexp.search(text) is not None:
                    text = info.regexp.sub(info.new_name, text)
                    name_list.append(info.name)
            if len(name_list) > 0:
                line = '%s is modified for %s' % ('portal_skins/' + path,
                                                  ', '.join(name_list))
                LOG('fixSkinNames', 0, line)
                msg += '%s\n' % line
                if not dry_run:
                    if skin.meta_type in fs_skin_spec:
                        with open(expandpath(skin.getObjectFSPath()),
                                  'w') as f:
                            f.write(text)
                    else:
                        REQUEST['BODY'] = text
                        skin.manage_FTPput(REQUEST, REQUEST.RESPONSE)

    # Check the portal types.
    for t in self.portal_types.objectValues():
        # Initial view name.
        text = t.immediate_view
        for info in info_list:
            if info.name == text:
                line = 'Initial view name of %s is modified for %s' % (
                    'portal_types/' + t.id, text)
                LOG('fixSkinNames', 0, line)
                msg += '%s\n' % line
                if not dry_run:
                    t.immediate_view = info.new_name
                break
        # Constructor path.
        text = getattr(t, 'constructor_path', None)
        if text is not None:
            for info in info_list:
                if info.name == text:
                    line = 'Constructor path of %s is modified for %s' % (
                        'portal_types/' + t.id, text)
                    LOG('fixSkinNames', 0, line)
                    msg += '%s\n' % line
                    if not dry_run:
                        t.constructor_path = info.new_name
                    break
        # Actions.
        for action in t.listActions():
            text = action.action.text
            for info in info_list:
                if info.regexp.search(text) is not None:
                    text = info.regexp.sub(info.new_name, text)
                    line = 'Action %s of %s is modified for %s' % (
                        action.getId(), 'portal_types/' + t.id, info.name)
                    LOG('fixSkinNames', 0, line)
                    msg += '%s\n' % line
                    if not dry_run:
                        action.action.text = text
                    break

    # Check the portal templates.
    template_tool = getattr(self, 'portal_templates', None)
    # Check the existence of template tool, because an older version of ERP5 does not have it.
    if template_tool is not None:
        for template in template_tool.contentValues(
                filter={'portal_type': 'Business Template'}):
            # Skins.
            skin_id_list = []
            name_list = []
            for skin_id in template.getTemplateSkinIdList():
                for info in info_list:
                    if info.name == skin_id:
                        name_list.append(skin_id)
                        skin_id = info.new_name
                        break
                skin_id_list.append(skin_id)
            if len(name_list) > 0:
                line = 'Skins of %s is modified for %s' % (
                    'portal_templates/' + template.getId(),
                    ', '.join(name_list))
                LOG('fixSkinNames', 0, line)
                msg += '%s\n' % line
                if not dry_run:
                    template.setTemplateSkinIdList(skin_id_list)
            # Paths.
            path_list = []
            name_list = []
            for path in template.getTemplatePathList():
                for info in info_list:
                    if info.regexp.search(path):
                        name_list.append(skin_id)
                        path = info.regexp.sub(info.new_name, path)
                        break
                path_list.append(path)
            if len(name_list) > 0:
                line = 'Paths of %s is modified for %s' % (
                    'portal_templates/' + template.getId(),
                    ', '.join(name_list))
                LOG('fixSkinNames', 0, line)
                msg += '%s\n' % line
                if not dry_run:
                    template.setTemplatePathList(path_list)

    # Workflows.
    for wf in self.portal_workflow.objectValues():
        # Transitions.
        for id in wf.transitions.objectIds():
            transition = wf.transitions._getOb(id)
            text = transition.actbox_url
            for info in info_list:
                if info.regexp.search(text) is not None:
                    text = info.regexp.sub(info.new_name, text)
                    line = 'Transition %s of %s is modified for %s' % (
                        id, 'portal_workflow/' + wf.id, info.name)
                    LOG('fixSkinNames', 0, line)
                    msg += '%s\n' % line
                    if not dry_run:
                        transition.actbox_url = text
                    break
        # Worklists.
        for id in wf.worklists.objectIds():
            worklist = wf.worklists._getOb(id)
            text = worklist.actbox_url
            for info in info_list:
                if info.regexp.search(text) is not None:
                    text = info.regexp.sub(info.new_name, text)
                    line = 'Worklist %s of %s is modified for %s' % (
                        id, 'portal_workflow/' + wf.id, info.name)
                    LOG('fixSkinNames', 0, line)
                    msg += '%s\n' % line
                    if not dry_run:
                        worklist.actbox_url = text
                    break
        # Scripts.
        for id in wf.scripts.objectIds():
            script = wf.scripts._getOb(id)
            text = script.manage_FTPget()
            name_list = []
            for info in info_list:
                if info.regexp.search(text) is not None:
                    text = info.regexp.sub(info.new_name, text)
                    name_list.append(info.name)
            if len(name_list) > 0:
                line = 'Script %s of %s is modified for %s' % (
                    id, 'portal_workflow/' + wf.id, ', '.join(name_list))
                LOG('fixSkinNames', 0, line)
                msg += '%s\n' % line
                if not dry_run:
                    REQUEST['BODY'] = text
                    script.manage_FTPput(REQUEST, REQUEST.RESPONSE)

    # Rename the skins.
    if not dry_run:
        for info in info_list:
            try:
                if info.meta_type in fs_skin_spec:
                    skin = self.portal_skins[info.folder][info.name]
                    old_path = expandpath(skin.getObjectFSPath())
                    new_path = info.regexp.sub(info.new_name, old_path)
                    if info.removed:
                        os.remove(old_path)
                    else:
                        os.rename(old_path, new_path)
                else:
                    folder = self.portal_skins[info.folder]
                    if info.removed:
                        folder.manage_delObjects([info.name])
                    else:
                        folder.manage_renameObjects([info.name],
                                                    [info.new_name])
            except:
                type, value, traceback = sys.exc_info()
                if info.removed:
                    line = 'WARNING: the skin %s could not be removed because of the exception %s: %s\n' % (
                        info.name, str(type), str(value))
                    LOG('fixSkinNames', 0, line)
                    msg += '%s\n' % line
                else:
                    line = 'WARNING: the skin %s could not be renamed to %s because of the exception %s: %s\n' % (
                        info.name, info.new_name, str(type), str(value))
                    LOG('fixSkinNames', 0, line)
                    msg += '%s\n' % line

    return msg