diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..6deafc2 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 diff --git a/scripts/dev_setup.py b/scripts/dev_setup.py index 6f2c6f5..5f83b83 100644 --- a/scripts/dev_setup.py +++ b/scripts/dev_setup.py @@ -9,6 +9,7 @@ import sys import os from subprocess import check_call, CalledProcessError + def py_command(command): try: print('Executing: ' + sys.executable + ' ' + command) @@ -18,9 +19,11 @@ def py_command(command): print(err, file=sys.stderr) sys.exit(1) + def pip_command(command): py_command('-m pip ' + command) + packages = [] packages.append('src/mvnfeed_modules/mvnfeed-cli-common') diff --git a/src/mvnfeed-cli/mvnfeed/__init__.py b/src/mvnfeed-cli/mvnfeed/__init__.py index fec9547..ece379c 100644 --- a/src/mvnfeed-cli/mvnfeed/__init__.py +++ b/src/mvnfeed-cli/mvnfeed/__init__.py @@ -1,2 +1,2 @@ import pkg_resources -pkg_resources.declare_namespace(__name__) \ No newline at end of file +pkg_resources.declare_namespace(__name__) diff --git a/src/mvnfeed-cli/mvnfeed/cli/__init__.py b/src/mvnfeed-cli/mvnfeed/cli/__init__.py index 039699b..a9dfa53 100644 --- a/src/mvnfeed-cli/mvnfeed/cli/__init__.py +++ b/src/mvnfeed-cli/mvnfeed/cli/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------------------------- import pkg_resources -pkg_resources.declare_namespace(__name__) \ No newline at end of file +pkg_resources.declare_namespace(__name__) diff --git a/src/mvnfeed-cli/mvnfeed/cli/__main__.py b/src/mvnfeed-cli/mvnfeed/cli/__main__.py index f623966..28e7eef 100644 --- a/src/mvnfeed-cli/mvnfeed/cli/__main__.py +++ b/src/mvnfeed-cli/mvnfeed/cli/__main__.py @@ -7,6 +7,7 @@ import sys from .mvnfeed_cli import MvnFeedCLI + def main(): try: mvnfeed_cli = MvnFeedCLI() @@ -15,5 +16,6 @@ def main(): except KeyboardInterrupt: sys.exit(1) + if __name__ == "__main__": main() diff --git a/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_cli.py b/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_cli.py index 710ef68..20ab1a7 100644 --- a/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_cli.py +++ b/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_cli.py @@ -1,10 +1,6 @@ from __future__ import print_function -import platform -import sys - from knack import CLI -from knack.events import EVENT_CLI_POST_EXECUTE, EVENT_CLI_PRE_EXECUTE from mvnfeed.cli.common.config import GLOBAL_CONFIG_DIR, CLI_ENV_VARIABLE_PREFIX, load_config from mvnfeed.cli.common.logmodule import init_logging from .mvnfeed_help import MvnFeedHelp @@ -14,6 +10,7 @@ CLI_NAME = "mvnfeed" CLI_PACKAGE_NAME = 'mvnfeed-cli' COMPONENT_PREFIX = 'mvnfeed-cli-' + class MvnFeedCLI(CLI): def __init__(self): super(MvnFeedCLI, self).__init__(cli_name=CLI_NAME, diff --git a/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_commands.py b/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_commands.py index 4da190b..197a33c 100644 --- a/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_commands.py +++ b/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_commands.py @@ -2,6 +2,7 @@ import knack from mvnfeed.cli.transfer.commands import load_transfer_commands from mvnfeed.cli.transfer.arguments import load_transfer_arguments + class MvnFeedCommandsLoader(knack.commands.CLICommandsLoader): def load_command_table(self, args): load_transfer_commands(self) @@ -9,4 +10,4 @@ class MvnFeedCommandsLoader(knack.commands.CLICommandsLoader): def load_arguments(self, command): load_transfer_arguments(self) - super(MvnFeedCommandsLoader, self).load_arguments(command) \ No newline at end of file + super(MvnFeedCommandsLoader, self).load_arguments(command) diff --git a/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_help.py b/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_help.py index 1813a5e..fa99e24 100644 --- a/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_help.py +++ b/src/mvnfeed-cli/mvnfeed/cli/mvnfeed_help.py @@ -1,13 +1,15 @@ from knack.help import CLIHelp from mvnfeed.cli.common.version import VERSION + class MvnFeedHelp(CLIHelp): def __init__(self, cli_ctx=None): # import command group help - import mvnfeed.cli.transfer._help + import mvnfeed.cli.transfer._help # noqa super(MvnFeedHelp, self).__init__(cli_ctx=cli_ctx, welcome_message=WELCOME_MESSAGE) + WELCOME_MESSAGE = """MvnFeed CLI {} Use `mvnfeed -h` to see available commands. diff --git a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/__init__.py b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/__init__.py index 039699b..a9dfa53 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/__init__.py +++ b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------------------------- import pkg_resources -pkg_resources.declare_namespace(__name__) \ No newline at end of file +pkg_resources.declare_namespace(__name__) diff --git a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/__init__.py b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/__init__.py index 039699b..a9dfa53 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/__init__.py +++ b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------------------------- import pkg_resources -pkg_resources.declare_namespace(__name__) \ No newline at end of file +pkg_resources.declare_namespace(__name__) diff --git a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/__init__.py b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/__init__.py index 039699b..a9dfa53 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/__init__.py +++ b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------------------------- import pkg_resources -pkg_resources.declare_namespace(__name__) \ No newline at end of file +pkg_resources.declare_namespace(__name__) diff --git a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/config.py b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/config.py index c37ef69..22cb936 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/config.py +++ b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/config.py @@ -13,12 +13,14 @@ REPOSITORY = 'repository.' URL = 'url' AUTHORIZATION = 'authorization' + def _get_config_dir(): codegen_config_dir = os.getenv('MVNFEED_CONFIG_DIR', None) or os.path.expanduser(os.path.join('~', '.mvnfeed')) if not os.path.exists(codegen_config_dir): os.makedirs(codegen_config_dir) return codegen_config_dir + GLOBAL_CONFIG_DIR = _get_config_dir() diff --git a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/logmodule.py b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/logmodule.py index 6f2553c..7fcad8a 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/logmodule.py +++ b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/logmodule.py @@ -5,6 +5,7 @@ import logging + def init_logging(filepath, level=logging.DEBUG): """ Initialize the logging module for the application. diff --git a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/version.py b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/version.py index 6ac5af5..789c38e 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/version.py +++ b/src/mvnfeed_modules/mvnfeed-cli-common/mvnfeed/cli/common/version.py @@ -3,4 +3,4 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -VERSION = "0.0.1" \ No newline at end of file +VERSION = "0.0.1" diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/__init__.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/__init__.py index 039699b..a9dfa53 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/__init__.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------------------------- import pkg_resources -pkg_resources.declare_namespace(__name__) \ No newline at end of file +pkg_resources.declare_namespace(__name__) diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/__init__.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/__init__.py index 039699b..a9dfa53 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/__init__.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------------------------- import pkg_resources -pkg_resources.declare_namespace(__name__) \ No newline at end of file +pkg_resources.declare_namespace(__name__) diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/__init__.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/__init__.py index ae49d1c..037e368 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/__init__.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/__init__.py @@ -6,10 +6,10 @@ import pkg_resources pkg_resources.declare_namespace(__name__) -import knack.help def load_params(_): - import knack.arguments + import knack.arguments # noqa + def load_commands(): - import knack.commands + import knack.commands # noqa diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/arguments.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/arguments.py index 77457e8..57ad38e 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/arguments.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/arguments.py @@ -5,6 +5,7 @@ import knack + def load_transfer_arguments(cli_command_loader): with knack.arguments.ArgumentsContext(cli_command_loader, 'config stage_dir') as ac: ac.argument('path', options_list=('--path')) diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/cleanup.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/cleanup.py index b1a407a..c53d807 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/cleanup.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/cleanup.py @@ -3,9 +3,9 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import logging import os + def cleanup_file(type, input, output): """ Cleanup input file. @@ -61,7 +61,7 @@ def _cleanup_gradle(input, output): packages.append(line[start:end]) continue - if not '\--- ' in line and not '+--- ' in line: + if '\\--- ' not in line and '+--- ' not in line: # not a package line continue if ' -> ' in line or ' (*)' in line or ' (n)' in line: diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/commands.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/commands.py index 4907262..566d5ea 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/commands.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/commands.py @@ -3,9 +3,9 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import knack from knack.commands import CommandGroup + def load_transfer_commands(cli_command_loader): with CommandGroup(cli_command_loader, 'artifact', 'mvnfeed.cli.transfer.{}') as g: g.command('transfer', 'transfer#transfer_artifact') diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/configuration.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/configuration.py index 3242631..c56ca66 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/configuration.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/configuration.py @@ -6,10 +6,11 @@ import base64 import getpass -from mvnfeed.cli.common.config import REPOSITORY, AUTHORIZATION, URL, URL, repo_section_name, load_config, save_config +from mvnfeed.cli.common.config import REPOSITORY, AUTHORIZATION, URL, repo_section_name, load_config, save_config STAGE_DIR_CONFIGNAME = 'stage_dir' + def set_stagedir(path): """ Sets the output directory where dependencies will be staged. @@ -112,4 +113,4 @@ def get_stagedir(config): def _default_value(input): if input is None: return '' - return input \ No newline at end of file + return input diff --git a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/transfer.py b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/transfer.py index 39aab2c..ec1e301 100644 --- a/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/transfer.py +++ b/src/mvnfeed_modules/mvnfeed-cli-transfer/mvnfeed/cli/transfer/transfer.py @@ -98,7 +98,7 @@ def _transfer_single_artifact(name, from_repository, to_repository, stage_dir, t artifact_path = group_id.replace('.', '/') + '/' + artifact_name + '/' + version - if artifact_type in [ 'jar', 'war' ]: + if artifact_type in ['jar', 'war']: files2transfer = _java_artifacts(artifact_fullname, artifact_type, artifact_path, transfer_deps) else: files2transfer = _untyped_artifacts(artifact_fullname, artifact_type, artifact_path, transfer_deps) @@ -117,7 +117,7 @@ def _transfer_single_artifact(name, from_repository, to_repository, stage_dir, t _download_file(from_repository, artifact_relativepath, outfile) if not os.path.exists(outfile): logging.info('%s was not downloaded. Skipping', outfile) - if file2transfer['target'] == True: + if file2transfer['target']: logging.warning('%s was not found in the repository', file2transfer['name']) continue @@ -134,8 +134,9 @@ def _transfer_single_artifact(name, from_repository, to_repository, stage_dir, t parent_group_id = _findNodeValue(parentNode, 'groupId') parent_artifact_id = _findNodeValue(parentNode, 'artifactId') parent_version = _findNodeValue(parentNode, 'version') + parent_path = parent_group_id.replace('.', '/') + '/' + parent_artifact_id + '/' + parent_version - files2transfer.append(_pom_artifact(parent_artifact_id + '-' + parent_version, parent_group_id.replace('.', '/') + '/' + parent_artifact_id + '/' + parent_version)) + files2transfer.append(_pom_artifact(parent_artifact_id + '-' + parent_version, parent_path)) if 'transfer_deps' not in file2transfer or not file2transfer['transfer_deps']: logging.info('not transferring dependencies from %s', file2transfer['name']) @@ -162,7 +163,8 @@ def _transfer_single_artifact(name, from_repository, to_repository, stage_dir, t # if no version has been defined, than it's getting potentially # tricky so let's just give up and let the user deal with it if dep_version is None: - logging.error('missing explicit version for %s:%s in %s. Skipping', dep_group_id, dep_artifact_id, file2transfer['name']) + logging.error('missing explicit version for %s:%s in %s. Skipping', + dep_group_id, dep_artifact_id, file2transfer['name']) continue # let's download the dependency @@ -170,6 +172,7 @@ def _transfer_single_artifact(name, from_repository, to_repository, stage_dir, t artifact_path = dep_group_id.replace('.', '/') + '/' + dep_artifact_id + '/' + dep_version files2transfer.extend(_java_artifacts(artifact_fullname, 'jar', artifact_path, transfer_deps)) + # Definitions of the artifacts to download: # - name: name of the artifact # - path: full path of the artifact, will be prepended to the urls @@ -248,7 +251,7 @@ def _download_file(from_repository, path, filename, length=16*1024): if os.path.exists(filename): logging.debug('%s already downloaded', filename) - if not URL in from_repository or not from_repository[URL]: + if URL not in from_repository or not from_repository[URL]: raise ValueError('Repository missing url: ' + get_repository_shortname(from_repository)) url = _append_url(from_repository[URL], path) @@ -273,16 +276,16 @@ def _already_uploaded(to_repository, path): """ Return True if the file was already uploaded. """ - if not URL in to_repository or not to_repository[URL]: + if URL not in to_repository or not to_repository[URL]: raise ValueError('Repository missing upload url: ' + get_repository_shortname(to_repository)) url = _append_url(to_repository[URL], path) if AUTHORIZATION in to_repository and to_repository[AUTHORIZATION]: logging.debug('authorization header added') - headers = { 'Authorization': to_repository[AUTHORIZATION] } + headers = {'Authorization': to_repository[AUTHORIZATION]} else: logging.debug('no authorization configured') - headers = { } + headers = {} try: response = requests.head(url, headers=headers) @@ -302,17 +305,17 @@ def _upload_file(to_repository, path, filename): logging.debug('missing file to upload, skipping %s', filename) return False - if not URL in to_repository or not to_repository[URL]: + if URL not in to_repository or not to_repository[URL]: raise ValueError('Repository missing upload url: ' + get_repository_shortname(to_repository)) url = _append_url(to_repository[URL], path) logging.debug('uploading to ' + url) if AUTHORIZATION in to_repository and to_repository[AUTHORIZATION]: logging.debug('authorization header added') - headers = { 'Authorization': to_repository[AUTHORIZATION] } + headers = {'Authorization': to_repository[AUTHORIZATION]} else: logging.debug('no authorization configured') - headers = { } + headers = {} try: with open(filename, 'rb') as file: