def integration_artifactory_path_repo(artifactory): """ Create repo if not exist and remove all files from this repo :param artifactory: :return: """ # Create repo if not exist name = 'integration-artifactory-path-repo' repo_ = artifactory.find_repository_local(name) if repo_ is None: repo_ = RepositoryLocal(artifactory=artifactory, name=name) repo_.create() # Remove all file from repo repo_path = ArtifactoryPath(str(artifactory) + "/" + name, auth=artifactory.auth) for path_ in repo_path.glob('*'): path_.unlink() yield repo_
def search_packages_dohq(self, url, dictionary={}, **kwargs): """ This method parses the remote artifactory repository structure and chooses those files that are having the extension .py or .whl. Uses dohq-artifactory API. :param url (str): remote artifactory repository address :param dictionary (dict): dict where will be passed the result :**kwargs may contain 'login', 'password' :return dict formatted like {'module link', 'module name'} """ if 'login' in kwargs and 'password' in kwargs: path = ArtifactoryPath(url, auth=(kwargs['login'], kwargs['password'])) else: path = ArtifactoryPath(url, auth=(self.login, self.password)) for p in path.glob('**/*.*'): link = str(p) if link.endswith('.py') or link.endswith('.whl'): dictionary.update({link: link.split('/')[-1]}) return dictionary
#!/usr/bin/python3 import smtplib from artifactory import ArtifactoryPath from email.mime.text import MIMEText SMTP_IP = 'localhost' SEBSY_URL = "http://*****:*****@gmail.com' msg['To'] = '*****@*****.**' s = smtplib.SMTP(SMTP_IP) s.send_message(msg) s.quit() with open("/tmp/file.txt", "a") as myfile: myfile.write(str(p))
def get_packages(self, source, parser, downloader, list_or_file_path): _auth_type = source.args['auth_type'].lower() if 'auth_type' in source.args else 'simple' _art_auth = {} if 'auth' in source.args: if _auth_type == 'simple': _art_auth['auth'] = tuple(source.args['auth']) elif _auth_type == 'cert': _art_auth['cert'] = os.path.realpath(source.args['auth']) if 'verify' in source.args: _art_auth['verify'] = source.args['verify'].lower in ['true', 'yes', '1'] _pkg_name_col = self._config.name_column _packages_found = {} _pkg_name_old = "" for _paths in parser.get_paths(list_or_file_path, source): _packages = [] _pkg_name = _paths['params'][_pkg_name_col] if _pkg_name != _pkg_name_old: _pkg_name_old = _pkg_name print_stdout( '{}: {}'.format(_pkg_name, {k: v for k, v in _paths['params'].items() if k != _pkg_name_col})) for _path in _paths['paths']: _path_fixed, _path_pattern = parser.split_fixed_pattern(_path) _repo_paths = ArtifactoryPath(_path_fixed, **_art_auth) for _repo_path in _repo_paths.glob(_path_pattern): _mark = 'found' if parser.validate_path(str(_repo_path), _paths['params']): _mark = 'match' if parser.validate(_repo_path.properties, 'properties', _paths['params']): _mark = 'valid' _packages += [_repo_path] print_stdout(' {}: {}'.format(_mark, str(_repo_path))) _package = None if _packages: _packages = parser.filter_one(_packages, _paths['params']) if type(_packages) is dict: _packages = [_packages] if len(_packages) == 1: # one package found: ok! # _stat = _packages[0]['path'].stat() # _stat = {k: getattr(_stat, k, None) for k in ('ctime', # 'mtime', # 'md5', # 'sha1', # 'size')} _package = Package(_pkg_name, _packages[0]['path'], _paths['params'], downloader, self, parser, _packages[0]['params']) # , _stat) _mark = 'chosen' print_stdout(' {}: {}'.format(_mark, str(_packages[0]['path']))) elif len(_packages) > 1: # TODO: multiple packages found: wtf?! raise CrosspmException( CROSSPM_ERRORCODE_MULTIPLE_DEPS, 'Multiple instances found for package [{}] not found.'.format(_pkg_name) ) else: # Package not found: may be error, but it could be in other source. pass else: # Package not found: may be error, but it could be in other source. pass # _pkg_name = self._config.get_column_name(0) # raise CrosspmException( # CROSSPM_ERRORCODE_PACKAGE_NOT_FOUND, # 'Package [{}] not found.'.format(_pkg_name) # ) if (_package is not None) or (not self._config.no_fails): _added, _package = downloader.add_package(_pkg_name, _package) else: _added = False if _package is not None: _pkg_name = _package.get_name_and_path(True) if _added or (_package is not None): if (_package is not None) or (not self._config.no_fails): if (_package is not None) or (_packages_found.get(_pkg_name, None) is None): _packages_found[_pkg_name] = _package if _added and (_package is not None): if downloader.do_load: _package.download(downloader.packed_path) _deps_file = _package.get_file(self._config.deps_lock_file_name, downloader.temp_path) if _deps_file: _package.find_dependencies(_deps_file) return _packages_found
def get_packages(self, source, parser, downloader, list_or_file_path): _auth_type = source.args['auth_type'].lower( ) if 'auth_type' in source.args else 'simple' _art_auth = {} if 'auth' in source.args: if _auth_type == 'simple': _art_auth['auth'] = tuple(source.args['auth']) elif _auth_type == 'cert': _art_auth['cert'] = os.path.realpath(source.args['auth']) if 'verify' in source.args: _art_auth['verify'] = source.args['verify'].lower in [ 'true', 'yes', '1' ] _pkg_name_col = self._config.name_column _packages_found = {} _pkg_name_old = "" for _paths in parser.get_paths(list_or_file_path, source): _packages = [] _pkg_name = _paths['params'][_pkg_name_col] if _pkg_name != _pkg_name_old: _pkg_name_old = _pkg_name print_stdout('{}: {}'.format( _pkg_name, { k: v for k, v in _paths['params'].items() if k != _pkg_name_col })) for _path in _paths['paths']: _path_fixed, _path_pattern = parser.split_fixed_pattern(_path) _repo_paths = ArtifactoryPath(_path_fixed, **_art_auth) for _repo_path in _repo_paths.glob(_path_pattern): _mark = 'found' if parser.validate_path(str(_repo_path), _paths['params']): _mark = 'match' if parser.validate(_repo_path.properties, 'properties', _paths['params']): _mark = 'valid' _packages += [_repo_path] print_stdout(' {}: {}'.format(_mark, str(_repo_path))) _package = None if _packages: _packages = parser.filter_one(_packages, _paths['params']) if type(_packages) is dict: _packages = [_packages] if len(_packages) == 1: # one package found: ok! # _stat = _packages[0]['path'].stat() # _stat = {k: getattr(_stat, k, None) for k in ('ctime', # 'mtime', # 'md5', # 'sha1', # 'size')} _package = Package(_pkg_name, _packages[0]['path'], _paths['params'], downloader, self, parser, _packages[0]['params']) # , _stat) _mark = 'chosen' print_stdout(' {}: {}'.format(_mark, str(_packages[0]['path']))) elif len(_packages) > 1: # TODO: multiple packages found: wtf?! raise CrosspmException( CROSSPM_ERRORCODE_MULTIPLE_DEPS, 'Multiple instances found for package [{}] not found.'. format(_pkg_name)) else: # Package not found: may be error, but it could be in other source. pass else: # Package not found: may be error, but it could be in other source. pass # _pkg_name = self._config.get_column_name(0) # raise CrosspmException( # CROSSPM_ERRORCODE_PACKAGE_NOT_FOUND, # 'Package [{}] not found.'.format(_pkg_name) # ) if (_package is not None) or (not self._config.no_fails): _added, _package = downloader.add_package(_pkg_name, _package) else: _added = False if _package is not None: _pkg_name = _package.get_name_and_path(True) if _added or (_package is not None): if (_package is not None) or (not self._config.no_fails): if (_package is not None) or (_packages_found.get( _pkg_name, None) is None): _packages_found[_pkg_name] = _package if _added and (_package is not None): if downloader.do_load: _package.download(downloader.packed_path) _deps_file = _package.get_file( self._config.deps_lock_file_name, downloader.temp_path) if _deps_file: _package.find_dependencies(_deps_file) return _packages_found