Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update artifactory.py #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@

""" artifactory: a python module for interfacing with JFrog Artifactory

This module is intended to serve as a logical descendant of pathlib
This module is intended to serve as a logical descendant of pathlib2
(https://docs.python.org/3/library/pathlib.html), a Python 3 module
for object-oriented path manipulations. As such, it implements
everything as closely as possible to the origin with few exceptions,
such as stat().

There are PureArtifactoryPath and ArtifactoryPath that can be used
to manipulate artifactory paths. See pathlib docs for details how
to manipulate artifactory paths. See pathlib2 docs for details how
pure paths can be used.
"""

import os
import sys
import errno
import pathlib
import pathlib2
import collections
import requests
import re
Expand Down Expand Up @@ -288,12 +288,12 @@ def encode_properties(parameters):
return '|'.join(result)


class _ArtifactoryFlavour(pathlib._Flavour):
class _ArtifactoryFlavour(pathlib2._Flavour):
"""
Implements Artifactory-specific pure path manipulations.
I.e. what is 'drive', 'root' and 'path' and how to split full path into
components.
See 'pathlib' documentation for explanation how those are used.
See 'pathlib2' documentation for explanation how those are used.

drive: in context of artifactory, it's the base URI like
http://mysite/artifactory
Expand All @@ -305,7 +305,7 @@ class _ArtifactoryFlavour(pathlib._Flavour):
sep = '/'
altsep = '/'
has_drv = True
pathmod = pathlib.posixpath
pathmod = pathlib2.posixpath

is_supported = (True)

Expand Down Expand Up @@ -405,7 +405,7 @@ def make_uri(self, path):
'children'])


class _ArtifactoryAccessor(pathlib._Accessor):
class _ArtifactoryAccessor(pathlib2._Accessor):
"""
Implements operations with Artifactory REST API
"""
Expand Down Expand Up @@ -624,7 +624,7 @@ def owner(self, pathobj):
"""
Returns file owner
This makes little sense for Artifactory, but to be consistent
with pathlib, we return modified_by instead, if available
with pathlib2, we return modified_by instead, if available
"""
stat = self.stat(pathobj)

Expand All @@ -637,7 +637,7 @@ def creator(self, pathobj):
"""
Returns file creator
This makes little sense for Artifactory, but to be consistent
with pathlib, we return created_by instead, if available
with pathlib2, we return created_by instead, if available
"""
stat = self.stat(pathobj)

Expand Down Expand Up @@ -824,7 +824,7 @@ class ArtifactoryOpensourceAccessor(_ArtifactoryAccessor):
pass


class PureArtifactoryPath(pathlib.PurePath):
class PureArtifactoryPath(pathlib2.PurePath):
"""
A class to work with Artifactory paths that doesn't connect
to Artifactory server. I.e. it supports only basic path
Expand All @@ -839,30 +839,30 @@ def __init__(self, accessor):
self._accessor = accessor


class ArtifactoryPath(pathlib.Path, PureArtifactoryPath):
class ArtifactoryPath(pathlib2.Path, PureArtifactoryPath):
"""
Implements fully-featured pathlib-like Artifactory interface
Implements fully-featured pathlib2-like Artifactory interface
Unless explicitly mentioned, all methods copy the behaviour
of their pathlib counterparts.
of their pathlib2 counterparts.

Note that because of peculiarities of pathlib.Path, the methods
Note that because of peculiarities of pathlib2.Path, the methods
that create new path objects, have to also manually set the 'auth'
field, since the copying strategy of pathlib.Path is not based
field, since the copying strategy of pathlib2.Path is not based
on regular constructors, but rather on templates.
"""
# Pathlib limits what members can be present in 'Path' class,
# Pathlib2 limits what members can be present in 'Path' class,
# so authentication information has to be added via __slots__
__slots__ = ('auth', 'verify', 'cert')

def __new__(cls, *args, **kwargs):
"""
pathlib.Path overrides __new__ in order to create objects
pathlib2.Path overrides __new__ in order to create objects
of different classes based on platform. This magic prevents
us from adding an 'auth' argument to the constructor.
So we have to first construct ArtifactoryPath by Pathlib and
So we have to first construct ArtifactoryPath by Pathlib2 and
only then add auth information.
"""
obj = pathlib.Path.__new__(cls, *args, **kwargs)
obj = pathlib2.Path.__new__(cls, *args, **kwargs)

cfg_entry = get_global_config_entry(obj.drive)
obj.auth = kwargs.get('auth', None)
Expand Down Expand Up @@ -1010,15 +1010,15 @@ def owner(self):
"""
Returns file owner.
This makes little sense for Artifactory, but to be consistent
with pathlib, we return modified_by instead, if available.
with pathlib2, we return modified_by instead, if available.
"""
return self._accessor.owner(self)

def creator(self):
"""
Returns file creator.
This makes little sense for Artifactory, but to be consistent
with pathlib, we return created_by instead, if available.
with pathlib2, we return created_by instead, if available.
"""
return self._accessor.creator(self)

Expand Down Expand Up @@ -1122,7 +1122,7 @@ def deploy_file(self,
target = self

if self.is_dir():
target = self / pathlib.Path(file_name).name
target = self / pathlib2.Path(file_name).name

with open(file_name, 'rb') as fobj:
target.deploy(fobj, md5, sha1, parameters)
Expand Down