def store(self, event=None): # get the verification URL v_url = self.verification_url # get the copyright information fields license_xml = etree.fromstring(api.getApp().license_doc) license = api.findField('license', api.getApp().items[0]) license_name = license_xml.find('license-name').text year = api.findField('year', api.getApp().items[0]) holder = api.findField('holder', api.getApp().items[0]) for item in api.getApp().items: # adapt the item to IEmbeddable if possible embeddable = zope.component.getGlobalSiteManager().getAdapters( [item,], IEmbeddable) if embeddable: for e in embeddable: # take e[1] since getAdapters returns a list of tuples -- # (name, adapter) e[1].embed(license, v_url, year, holder) # calculate the hash of each item # XXX see triple-x comment in store method of ia.py self.rdf = cctagutils.rdf.generate_rdfa( [n.getIdentifier() for n in api.getApp().items[1:]], license_name, license, v_url)
def __archiveId(self): """Generates an archive.org identifier from work metadata or embedded ID3 tags.""" id_pieces = [] creator = api.findField('holder') if creator: id_pieces.append(creator) title = api.findField('title') if title: id_pieces.append(title) archive_id = pyarchive.identifier.munge(" ".join(id_pieces)) try: id_avail = pyarchive.identifier.available(archive_id) except pyarchive.exceptions.MissingParameterException, e: id_avail = False
def validate(self, event=None): # determine the appropriate collection work_type = api.findField('format') if work_type: work_type = work_type.lower() else: # no work type; can not validate raise KeyError("work_type not specified.")
def validate(self, event=None): # determine the appropriate collection work_type = api.findField('format') if work_type: work_type = work_type.lower() else: # no work type; can not validate raise KeyError("work_type not specified.") if work_type == 'audio': self.archive_collection = pyarchive.const.OPENSOURCE_AUDIO self.submission_type = pyarchive.const.AUDIO elif work_type == 'video': self.archive_collection = pyarchive.const.OPENSOURCE_MOVIES self.submission_type = pyarchive.const.VIDEO else: self.archive_collection = pyarchive.const.OPENSOURCE_MEDIA self.submission_type = work_type = api.findField('format')
def store(self, event=None): # get the verification URL #v_url = "" titlei=api.findField('title') descriptioni=api.findField('description') tagsi=api.findField('keywords') tagList=tagsi.split(",") tagsi="" for tag in tagList: #Flickr is space delimited, so we must enclose keywords in double quotes if they have a space if tag.find(" ")>0: tag='"'+tag+'"' tagsi=tagsi+","+tag #Get the license information to transfer to Flickr license_xml = etree.fromstring(api.getApp().license_doc) license_full = license_xml.find('license-name').text license=license_full.split()[0] lic=0 #Choose the license, Flickr arbitrarily assigns a number to each license. Later, these should #be requested first before choosing, in case Flickr changes the system. Next to be updated if license == "Attribution": lic=4 elif license == "Attribution-NonCommercial": lic=2 elif license == "Attribution-NonCommercial-ShareAlike": lic=1 elif license == "Attribution-NonCommercial-NoDerivs": lic=3 elif license == "Attribution-NoDerivs": lic=6 elif license == "Attribution-ShareAlike": lic=5 #Make an Uploadr object and then upload everything. Must authenticate here automatically (gets Frob, Token, etc # in case the filesystem doesn't cache the token. uploadMe=Uploadr.Uploadr() uploadMe.authenticatePt2() i=0 for item in api.getApp().items[1:]: uploadMe.uploadImage(item.getIdentifier(),title=titlei,desc=descriptioni,tags=tagsi,license=lic) i+=1
def store(self, event=None): # generate the identifier and make sure it's available archive_id = self.__archiveId() # generate the verification url v_url = pyarchive.identifier.verify_url(archive_id) # get the copyright information fields license = api.findField('license', api.getApp().items[0]) year = api.findField('year', api.getApp().items[0]) holder = api.findField('holder', api.getApp().items[0]) for item in api.getApp().items: # adapt the item to IEmbeddable if possible embeddable = zope.component.getGlobalSiteManager().getAdapters( [item,], IEmbeddable) if embeddable: for e in embeddable: # take e[1] since getAdapters returns a list of tuples -- # (name, adapter) e[1].embed(license, v_url, year, holder) # create the submission object submission = pyarchive.submission.ArchiveItem( archive_id, self.archive_collection, self.submission_type, api.findField('title') ) # retrieve all metadata fields for the work (the root item) root_item = api.getApp().items[0] for g in api.getApp().groups: meta_dicts = [p6.metadata.interfaces.IMetadataStorage(root_item)] for m in meta_dicts: for k in m.keys(): submission[k] = m.getMetaValue(k) # now add the individual files to the submission for item in p6.api.getApp().items[1:]: # XXX we're passing in the filename instead of the item and this is really, really bad # XXX we should make pyarchive interface aware, give it it's own InputItem interface # XXX and then adapt our item to that. sub = submission.addFile(item.getIdentifier(), pyarchive.const.ORIGINAL, format = p6.metadata.interfaces.IMetadataProvider(item).getMetaValue("format"), claim = self.__claimString(license, v_url, year, holder) ) for g in p6.api.getApp().groups: meta_dicts = [p6.metadata.interfaces.IMetadataStorage(item)] for m in meta_dicts: for k in m.keys(): print 'setting %s to %s...' % (k, m.getMetaValue(k)) setattr(item, k, m.getMetaValue(k) or '') print submission.metaxml().getvalue() print submission.filesxml().getvalue() self.uri = submission.submit( self.credentials[0], self.credentials[1], callback=CallbackBridge()) return {'URI':self.uri}
def store(self, event=None): # generate the verification url v_url = pyarchive.identifier.verify_url(self.identifier) # get the copyright information fields license = api.findField('license', api.getApp().items[0]) year = api.findField('year', api.getApp().items[0]) holder = api.findField('holder', api.getApp().items[0]) for item in api.getApp().items: # adapt the item to IEmbeddable if possible embeddable = zope.component.getGlobalSiteManager().getAdapters( [item,], IEmbeddable) if embeddable: for e in embeddable: # take e[1] since getAdapters returns a list of tuples -- # (name, adapter) e[1].embed(license, v_url, year, holder) # create the submission object submission = pyarchive.submission.ArchiveItem( pyarchive.submission.UploadApplication("ccPublisher", const.version()) ) # set the submission identifier, collection, etc submission.identifier = self.identifier submission.collection = self.archive_collection submission.mediatype = self.submission_type submission.title = api.findField('title') # retrieve all metadata fields for the work (the root item) root_item = api.getApp().items[0] for g in api.getApp().groups: meta_dicts = [p6.metadata.interfaces.IMetadataStorage(root_item)] for m in meta_dicts: for k in m.keys(): submission[k] = m.getMetaValue(k) # now add the individual files to the submission for item in p6.api.getApp().items[1:]: # XXX we're passing in the filename instead of the item # XXX and this is really, really bad # XXX we should make pyarchive interface aware, give it # XXX it's own InputItem interface # XXX and then adapt our item to that. try: sub = submission.addFile(item.getIdentifier(), pyarchive.const.ORIGINAL, format = p6.metadata.interfaces.IMetadataProvider(item).getMetaValue("format"), claim = self.__claimString(license, v_url, year, holder) ) except IOError, e: # the file doesn't exist p6.api.showError(_("The selected file %s can not be found.")) sys.exit(2) for g in p6.api.getApp().groups: meta_dicts = [p6.metadata.interfaces.IMetadataStorage(item)] for m in meta_dicts: for k in m.keys(): print 'setting %s to %s...' % (k, m.getMetaValue(k)) setattr(item, k, m.getMetaValue(k) or '')
def store(self, event=None): # generate the identifier and make sure it's available archive_id = self.__archiveId() # generate the verification url v_url = pyarchive.identifier.verify_url(self.archive_collection, archive_id, self.submission_type) # get the copyright information fields license = api.findField('license', api.getApp().items[0]) year = api.findField('year', api.getApp().items[0]) holder = api.findField('holder', api.getApp().items[0]) for item in api.getApp().items: # adapt the item to IEmbeddable if possible embeddable = zope.component.getGlobalSiteManager().getAdapters( [item,], IEmbeddable) if embeddable: for e in embeddable: e.embed(license, v_url, year, holder) # create the submission object submission = pyarchive.submission.ArchiveItem( archive_id, self.archive_collection, self.submission_type, api.findField('title') ) # retrieve all metadata fields for the work (the root item) root_item = api.getApp().items[0] for g in api.getApp().groups: meta_dicts = [p6.metadata.interfaces.IMetadataStorage(root_item)] for m in meta_dicts: for k in m.keys(): submission[k] = m.getMetaValue(k) # now add the individual files to the submission for item in p6.api.getApp().items[1:]: sub = submission.addItem(item, pyarchive.const.ORIGINAL, claim = self.__claimString(license, v_url, year, holder) ) for g in p6.api.getApp().groups: meta_dicts = [p6.metadata.interfaces.IMetadataStorage(item)] for m in meta_dicts: for k in m.keys(): print 'setting %s to %s...' % (k, m.getMetaValue(k)) setattr(item, k, m.getMetaValue(k) or '') print submission.metaxml().getvalue() print submission.filesxml().getvalue() archive_URI = submission.submit( IMetadataStorage(self).getMetaValue('username'), IMetadataStorage(self).getMetaValue('password'),) return {'URI':archive_URI}