Commit d3ae7918 authored by Julien Muchembled's avatar Julien Muchembled

Fix ClientError/GitError when exporting a new Business Template

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44256 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c8397666
...@@ -33,7 +33,7 @@ from DateTime import DateTime ...@@ -33,7 +33,7 @@ from DateTime import DateTime
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
from ZTUtils import make_query from ZTUtils import make_query
from Products.ERP5VCS.WorkingCopy import \ from Products.ERP5VCS.WorkingCopy import \
WorkingCopy, NotAWorkingCopyError, Dir, File, selfcached WorkingCopy, NotAWorkingCopyError, NotVersionedError, Dir, File, selfcached
class GitError(EnvironmentError): class GitError(EnvironmentError):
def __init__(self, err, out, returncode): def __init__(self, err, out, returncode):
...@@ -223,8 +223,14 @@ class Git(WorkingCopy): ...@@ -223,8 +223,14 @@ class Git(WorkingCopy):
return self.aq_parent.download(self.working_copy) return self.aq_parent.download(self.working_copy)
def showOld(self, path): def showOld(self, path):
return self.git('show', 'HEAD:' + self.prefix + path, try:
strip=False, cwd=self.toplevel) return self.git('show', 'HEAD:' + self.prefix + path,
strip=False, cwd=self.toplevel)
except GitError, e:
err = e.args[0]
if ' does not exist in ' in err or ' exists on disk, but not in ' in err:
raise NotVersionedError(path)
raise
def getAuthor(self): def getAuthor(self):
portal = self.getPortalObject() portal = self.getPortalObject()
......
...@@ -37,7 +37,7 @@ from Products.ERP5Type.Message import translateString ...@@ -37,7 +37,7 @@ from Products.ERP5Type.Message import translateString
from Products.ERP5.Document.BusinessTemplate import BusinessTemplateFolder from Products.ERP5.Document.BusinessTemplate import BusinessTemplateFolder
from Products.ERP5VCS.WorkingCopy import \ from Products.ERP5VCS.WorkingCopy import \
WorkingCopy, Dir, File, chdir_working_copy, selfcached, \ WorkingCopy, Dir, File, chdir_working_copy, selfcached, \
NotAWorkingCopyError, VcsConflictError NotAWorkingCopyError, NotVersionedError, VcsConflictError
from Products.ERP5VCS.SubversionClient import \ from Products.ERP5VCS.SubversionClient import \
newSubversionClient, SubversionLoginError, SubversionSSLTrustError newSubversionClient, SubversionLoginError, SubversionSSLTrustError
...@@ -139,9 +139,14 @@ class Subversion(WorkingCopy): ...@@ -139,9 +139,14 @@ class Subversion(WorkingCopy):
return self.aq_parent.download('.') return self.aq_parent.download('.')
def showOld(self, path): def showOld(self, path):
from pysvn import Revision, opt_revision_kind from pysvn import ClientError, Revision, opt_revision_kind, svn_err
return self._getClient().cat(os.path.join(self.working_copy, path), try:
Revision(opt_revision_kind.base)) return self._getClient().cat(os.path.join(self.working_copy, path),
Revision(opt_revision_kind.base))
except ClientError, e:
if e.args[1][-1][1] in (errno.ENOENT, svn_err.entry_not_found):
raise NotVersionedError(path)
raise
@selfcached @selfcached
def info(self): def info(self):
......
...@@ -72,6 +72,9 @@ def selfcached(func): ...@@ -72,6 +72,9 @@ def selfcached(func):
class NotAWorkingCopyError(Exception): pass class NotAWorkingCopyError(Exception): pass
ModuleSecurityInfo(__name__).declarePublic('NotAWorkingCopyError') ModuleSecurityInfo(__name__).declarePublic('NotAWorkingCopyError')
class NotVersionedError(Exception): pass
ModuleSecurityInfo(__name__).declarePublic('NotVersionedError')
class BusinessTemplateNotInstalled(Exception): pass class BusinessTemplateNotInstalled(Exception): pass
ModuleSecurityInfo(__name__).declarePublic('BusinessTemplateNotInstalled') ModuleSecurityInfo(__name__).declarePublic('BusinessTemplateNotInstalled')
...@@ -200,7 +203,10 @@ class WorkingCopy(Implicit): ...@@ -200,7 +203,10 @@ class WorkingCopy(Implicit):
def newRevision(self): def newRevision(self):
path = os.path.join('bt', 'revision') path = os.path.join('bt', 'revision')
revision = int(self.showOld(path)) + 1 try:
revision = int(self.showOld(path)) + 1
except NotVersionedError:
return 1
file = open(os.path.join(self.working_copy, path), 'w') file = open(os.path.join(self.working_copy, path), 'w')
try: try:
file.write(str(revision)) file.write(str(revision))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment