예제 #1
0
 def id_quote(self, s, mapping={
     '\x20': '_',
     '-': '_',
     '/': '_',
 }):
     warn(self, 'id_quote', 'Products.zms.standard.id_quote')
     return standard.id_quote(s, mapping)
예제 #2
0
    def doi(self):
      request = self.REQUEST
      RESPONSE =  request.RESPONSE
      zmscontext = self.getDocumentElement()
      path_ = 'index_html'

      if request['traverse_subpath']:
        path_ = standard.id_quote('_'.join(request['traverse_subpath']))

      catalog = self.get_catalog()
      query = {'zcat_attr_dc_identifier_doi':path_}
      rows = catalog(query)

      for x in rows:
        # ### test ####
        # print x['get_uid']
        # print zmscontext.getLinkObj('{$%s}'%x['get_uid'])
        # print zmscontext.getLinkObj('{$%s}'%x['get_uid']).absolute_url()
        # return printed
        # #############
        ob = zmscontext.getLinkObj('{$%s}'%x['get_uid'])
        RESPONSE.redirect(ob.absolute_url())
        return standard.FileFromData(zmscontext,ob.absolute_url())

      # Return a string identifying this script.
      return standard.FileFromData(zmscontext,"'%s' not found!"%path_)
예제 #3
0
 def localFiles(self, provider, ids=None):
     standard.writeLog(self, "[localFiles]: provider=%s" % str(provider))
     l = {}
     local = provider.provideRepository(ids)
     for id in local:
         o = local[id]
         filename = o.get('__filename__', [id, '__init__.py'])
         # Write python-representation.
         py = []
         py.append('class %s:' % id.replace('.', '_').replace('-', '_'))
         py.append('\t"""')
         py.append('\tpython-representation of %s' % o['id'])
         py.append('\t"""')
         py.append('')
         e = sorted([
             x for x in o if not x.startswith('__') and x == x.capitalize()
             and isinstance(o[x], list)
         ])
         keys = sorted(
             [x for x in o if not x.startswith('__') and x not in e])
         for k in keys:
             v = o.get(k)
             py.append('\t# %s' % k.capitalize())
             py.append('\t%s = %s' %
                       (standard.id_quote(k),
                        standard.str_json(v,
                                          encoding="utf-8",
                                          formatted=True,
                                          level=2,
                                          allow_booleans=False)))
             py.append('')
         for k in e:
             v = o.get(k)
             if v and isinstance(v, list):
                 py.append('\t# %s' % k.capitalize())
                 py.append('\tclass %s:' %
                           standard.id_quote(k).capitalize())
                 for i in v:
                     if 'id' in i:
                         ob = i.get('ob')
                         if ob is not None:
                             fileexts = {
                                 'DTML Method': '.dtml',
                                 'DTML Document': '.dtml',
                                 'External Method': '.py',
                                 'Page Template': '.zpt',
                                 'Script (Python)': '.py',
                                 'Z SQL Method': '.zsql'
                             }
                             fileprefix = i['id'].split('/')[-1]
                             data = zopeutil.readData(ob)
                             # if type(data) is unicode:
                             #   data = standard.pystr2(data)
                             version = ''
                             if hasattr(ob, '_p_mtime'):
                                 version = standard.getLangFmtDate(
                                     DateTime(ob._p_mtime).timeTime(),
                                     'eng')
                             d = {}
                             d['id'] = id
                             d['filename'] = os.path.sep.join(
                                 filename[:-1] + [
                                     '%s%s' %
                                     (fileprefix,
                                      fileexts.get(ob.meta_type, ''))
                                 ])
                             d['data'] = data
                             d['version'] = version
                             d['meta_type'] = ob.meta_type
                             l[d['filename']] = d
                         if 'ob' in i:
                             del i['ob']
                         try:
                             py.append(
                                 '\t\t%s = %s' %
                                 (self.id_quote(i['id']),
                                  standard.str_json(i,
                                                    encoding="utf-8",
                                                    formatted=True,
                                                    level=3,
                                                    allow_booleans=False)))
                         except:
                             py.append(
                                 '\t\t# ERROR: ' + standard.writeError(
                                     self, 'can\'t localFiles \'%s\'' %
                                     i['id']))
                         py.append('')
         d = {}
         d['__icon__'] = o.get('__icon__')
         d['__description__'] = o.get('__description__')
         d['id'] = id
         d['filename'] = os.path.sep.join(filename)
         d['data'] = '\n'.join(py)
         try:
             d['version'] = [
                 int(x) for x in o.get('revision', '0.0.0').split('.')
             ]
         except:
             d['version'] = [0, 0, 0]
         d['meta_type'] = 'Script (Python)'
         l[d['filename']] = d
     return l