Exemplo n.º 1
0
    def generate_id(self, session):
        if self.useUUID:
            return gen_uuid()

        cxn = self._openDb(session, 'digest')
        if cxn is None:
            cxn = self._openDb(session, 'database')
        if (self.currentId == -1 or session.environment == "apache"):
            c = cxn.cursor()
            item = c.last()
            if item:
                # Might need to out normalise key
                key = item[0]
                if self.outIdNormalizer:
                    key = self.outIdNormalizer.process_string(session, key)
                    if not type(key) in (int, long):
                        self.useUUID = 1
                        key = gen_uuid()
                    else:
                        key += 1
                else:
                    key = long(key)
                    key += 1
            else:
                key = 0
        else:
            key = self.currentId + 1
        self.currentId = key
        return key
Exemplo n.º 2
0
    def generate_id(self, session):
        if self.useUUID:
            return gen_uuid()

        cxn = self._openDb(session, 'digest')
        if cxn == None:
            cxn = self._openDb(session, 'database')
        if (self.currentId == -1 or session.environment == "apache"):
            c = cxn.cursor()
            item = c.last()
            if item:
                # might need to out normalise key
                key = item[0]
                if self.outIdNormalizer:
                    key = self.outIdNormalizer.process_string(session, key)
                    if not type(key) in (int, long):
                        self.useUUID = 1
                        key = gen_uuid()
                    else:
                        key += 1
                else:
                    key = long(key)
                    key += 1
            else:
                key = 0
        else:
            key = self.currentId +1
        self.currentId = key
        return key
Exemplo n.º 3
0
 def _get_metsWrapper(self, doc):
     # Get a generic METS wrapper for the given Document
     # Find/Generate identifiers and labels
     objid = gen_uuid()
     # Set up METS root and header
     mets = METS.mets(
         {
             'ID': '/'.join([objid, 'mets']),
             'OBJID': objid,
             'TYPE': 'ZIPFILE'
         },
         METS.metsHdr(
             {
                 'ID': '/'.join([objid, 'metsHdr']),
                 'CREATEDDATE': time.strftime('%Y-%m-%dT%H:%M:%S%Z')
             },
             METS.agent(
                 {
                     'ROLE': "CREATOR",
                     'TYPE': "OTHER",
                     'OTHERTYPE': 'SOFTWARE'
                 }, METS.name("Cheshire3"),
                 METS.note("METS instance was created by a Cheshire3 object"
                           " of type {0} identified as {1}"
                           "".format(type(self).__name__, self.id)))),
         METS.dmdSec(), METS.amdSec(),
         METS.fileSec(
             METS.fileGrp({'ID': '/'.join([objid, 'fileGrp', '0001'])})))
     # Set a human readable label if possible
     if doc.filename:
         mets.set("LABEL", os.path.abspath(doc.filename))
     elif doc.id:
         mets.set("LABEL", doc.id)
     return mets
Exemplo n.º 4
0
 def _get_metsWrapper(self, doc):
     # Get a generic METS wrapper for the given Document
     # Find/Generate identifiers and labels
     objid = gen_uuid()
     # Set up METS root and header
     mets = METS.mets(
         {'ID': '/'.join([objid, 'mets']),
          'OBJID': objid,
          'TYPE': 'ZIPFILE'
          },
         METS.metsHdr(
             {'ID': '/'.join([objid, 'metsHdr']),
              'CREATEDDATE': time.strftime('%Y-%m-%dT%H:%M:%S%Z')
              },
             METS.agent(
                 {'ROLE': "CREATOR",
                  'TYPE': "OTHER",
                  'OTHERTYPE': 'SOFTWARE'
                  },
                 METS.name("Cheshire3"),
                 METS.note(
                     "METS instance was created by a Cheshire3 object"
                     " of type {0} identified as {1}"
                     "".format(type(self).__name__, self.id)
                 )
             )
         ),
         METS.dmdSec(),
         METS.amdSec(),
         METS.fileSec(
             METS.fileGrp({'ID': '/'.join([objid, 'fileGrp', '0001'])})
         )
     )
     # Set a human readable label if possible
     if doc.filename:
         mets.set("LABEL", os.path.abspath(doc.filename))
     elif doc.id:
         mets.set("LABEL", doc.id)
     return mets