Cleanup the code with flake8 (#5)
This commit is contained in:
Родитель
a221fc30e1
Коммит
0b994e14f4
|
@ -0,0 +1,2 @@
|
|||
[flake8]
|
||||
max-line-length = 120
|
|
@ -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')
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
super(MvnFeedCommandsLoader, self).load_arguments(command)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import logging
|
||||
|
||||
|
||||
def init_logging(filepath, level=logging.DEBUG):
|
||||
"""
|
||||
Initialize the logging module for the application.
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
# Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
VERSION = "0.0.1"
|
||||
VERSION = "0.0.1"
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
return input
|
||||
|
|
|
@ -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:
|
||||
|
|
Загрузка…
Ссылка в новой задаче