# Gosh! How unlucky, same size, same checksum but not same
# content!
pass
returnFalse
defpropose_unique_docname(self,docname):
"""Propose a unique docname."""
docname=normalize_docname(docname)
goodname=docname
i=1
whilegoodnameinself.get_bibdoc_names():
i+=1
goodname="%s_%s"%(docname,i)
returngoodname
defmerge_bibdocs(self,docname1,docname2):
"""This method merge docname2 into docname1.
Given all the formats of the latest version of docname2 the files
are added as new formats into docname1.
Docname2 is marked as deleted.
This method fails if at least one format in docname2 already exists
in docname1. (In this case the two bibdocs are preserved)
Comments and descriptions are also copied and if docname2 has an icon
and docname1 has not, the icon is imported.
If docname2 has a restriction(status) and docname1 has not the
restriction is imported."""
bibdoc1=self.get_bibdoc(docname1)
bibdoc2=self.get_bibdoc(docname2)
## Check for possibility
forbibdocfileinbibdoc2.list_latest_files():
format=bibdocfile.get_format()
ifbibdoc1.format_already_exists_p(format):
raiseInvenioWebSubmitFileError('Format %s already exists in bibdoc %s of record %s. It\'s impossible to merge bibdoc %s into it.'%(format,docname1,self.id,docname2))
"""Algorithm that transform an a broken/old bibdoc into a coherent one:
i.e. the corresponding folder will have files named after the bibdoc
name. Proper .recid, .type, .md5 files will be created/updated.
In case of more than one file with the same format revision a new bibdoc
will be created in order to put does files.
Returns the list of newly created bibdocs if any.
"""
bibdoc=self.get_bibdoc(docname)
versions={}
res=[]
new_bibdocs=[]# List of files with the same version/format of
# existing file which need new bibdoc.
counter=0
zero_version_bug=False
ifos.path.exists(bibdoc.basedir):
forfilenameinos.listdir(bibdoc.basedir):
iffilename[0]!='.'and';'infilename:
name,version=filename.split(';')
try:
version=int(version)
exceptValueError:
# Strange name
register_exception()
raiseInvenioWebSubmitFileError,"A file called %s exists under %s. This is not a valid name. After the ';' there must be an integer representing the file revision. Please, manually fix this file either by renaming or by deleting it."%(filename,bibdoc.basedir)
raiseInvenioWebSubmitFileError,"Error in renaming '%s' to '%s': '%s'"%('%s/%s'%(bibdoc.basedir,filename),'%s/%s'%(bibdoc.basedir,new_name),e)
ifversions[version].has_key(format):
new_bibdocs.append((new_name,version))
else:
versions[version][format]=new_name
counter+=1
eliffilename[0]!='.':
# Strange name
register_exception()
raiseInvenioWebSubmitFileError,"A file called %s exists under %s. This is not a valid name. There should be a ';' followed by an integer representing the file revision. Please, manually fix this file either by renaming or by deleting it."%(filename,bibdoc.basedir)
raiseInvenioWebSubmitFileError,"A file for docname '%s' for the recid '%s' already exists for the format '%s'"%(self.docname,self.recid,docfile.get_format())