Skip to content

Commit

Permalink
cherry-pick jfrog and fix bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
xuqi2024 committed Apr 26, 2024
1 parent 0f16a2e commit a03424e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ __pycache__/
/dist/
/htmlcov
/pym/bob/version.py
**/__pycache__/
28 changes: 18 additions & 10 deletions pym/bob/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def _downloadPackage(self, buildId, suffix, audit, content, caches, workspace):
self._extract(fo, audit, content)
return (True, None, None)
except ArtifactNotFoundError:
return (False, "not found", WARNING)
return (False, "Not found in the backend", WARNING)
except ArtifactDownloadError as e:
return (False, e.reason, WARNING)
except BuildError as e:
Expand Down Expand Up @@ -437,10 +437,11 @@ def _downloadLocalFile(self, key, suffix):
# Set default signal handler so that KeyboardInterrupt is raised.
# Needed to gracefully handle ctrl+c.
signal.signal(signal.SIGINT, signal.default_int_handler)

try:
with self._openDownloadFile(key, suffix) as (name, fileobj):
ret = readFileOrHandle(name, fileobj)


return (ret, None, None)
except ArtifactNotFoundError:
return (None, "not found", WARNING)
Expand All @@ -450,6 +451,8 @@ def _downloadLocalFile(self, key, suffix):
raise
except OSError as e:
raise BuildError("Cannot download file: " + str(e))
except Exception as e:
raise BuildError("Other " + str(e))
finally:
# Restore signals to default so that Ctrl+C kills process. Needed
# to prevent ugly backtraces when user presses ctrl+c.
Expand Down Expand Up @@ -1128,11 +1131,11 @@ def __makeBlobName(buildId, suffix):
packageResultId[4:] + suffix])

def _remoteName(self, buildId, suffix):
a = "{}/{}".format(self.__url, self.__makeBlobName(buildId, suffix))
return "{}/{}".format(self.__url, self.__makeBlobName(buildId, suffix))

def _makeArtifactoryPath(self, blobName):
from artifactory import ArtifactoryPath

if self.__username and self.__key:
return ArtifactoryPath(
"{}/{}".format(self.__url, blobName.replace(os.sep, '_')),
Expand All @@ -1148,27 +1151,31 @@ def _makeArtifactoryPath(self, blobName):
def _openDownloadFile(self, buildId, suffix):
from artifactory import ArtifactoryPath
try:
fd = self._makeArtifactoryPath(self.__makeBlobName(buildId,suffix)).open()
fd = self._makeArtifactoryPath(self.__makeBlobName(buildId,suffix))

if not fd.exists():
raise ArtifactNotFoundError()
fd = fd.open()
return ArtifactoryDownloader(fd)
except RuntimeError as e:
raise ArtifactDownloadError(str(e))

def _openUploadFile(self, buildId, suffix):
def _openUploadFile(self, buildId, suffix ,overwrite):
blobName = self.__makeBlobName(buildId,suffix)
from artifactory import ArtifactoryPath
try:
fd = self._makeArtifactoryPath(blobName)
try:
fd.open()
if fd.exists():

if not overwrite and fd.exists():
raise ArtifactExistsError()
except RuntimeError:
pass
except RuntimeError as e:
raise ArtifactUploadError(str(e))
(tmpFd, tmpName) = mkstemp()
os.close(tmpFd)
return ArtifactoryUploader(self, fd, tmpName, blobName)
return ArtifactoryUploader(self, fd, tmpName, blobName, overwrite)

def upload(self, step, buildIdFile, fingerprintFile, tgzFile):
if not self.canUploadJenkins():
Expand Down Expand Up @@ -1232,7 +1239,7 @@ def scriptDownload(args):
tmpName = None
try:
(tmpFd, tmpName) = mkstemp(dir=".")

path = archive._makeArtifactoryPath(remoteBlob)

with path.open() as fd:
Expand Down Expand Up @@ -1301,10 +1308,11 @@ def __exit__(self, exc_type, exc_value, traceback):
return False

class ArtifactoryUploader:
def __init__(self, artifactory, fd, name, remoteName):
def __init__(self, artifactory, fd, name, remoteName, overwrite):
self.__artifactory = artifactory
self.__name = name
self.__remoteName = remoteName
self.__overwrite = overwrite

def __enter__(self):
return (self.__name, None)
Expand Down
1 change: 1 addition & 0 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,7 @@ def __init__(self):
schema.Optional('key') : str,
schema.Optional('username') : str,
})

self.__backends = {
'none' : schema.Schema(baseArchive),
'file' : schema.Schema(fileArchive),
Expand Down

0 comments on commit a03424e

Please sign in to comment.