From 7c2e4a9634d503532c823fb337d8a3bafcb6a170 Mon Sep 17 00:00:00 2001 From: robertatakenaka Date: Thu, 19 Apr 2018 13:14:34 -0300 Subject: [PATCH 1/3] Atualizacao do version.txt --- src/scielo/bin/cfg/version.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scielo/bin/cfg/version.txt b/src/scielo/bin/cfg/version.txt index 67fa4af08..709ac5537 100644 --- a/src/scielo/bin/cfg/version.txt +++ b/src/scielo/bin/cfg/version.txt @@ -1,5 +1,5 @@ -4.0.095 Teste 29/03/2018 -======================== +4.0.095 29/03/2018 +================== - Installation with proxy - Markup XML From 978ad37fb8bd84cc8d7b84e398bcc99030b6adfc Mon Sep 17 00:00:00 2001 From: robertatakenaka Date: Thu, 19 Apr 2018 17:42:33 -0300 Subject: [PATCH 2/3] 40095_install_requirements - questoes de proxy e de ambiente virtual --- src/scielo/bin/xml/app_modules/__init__.py | 44 ++++------ .../xml/app_modules/app/config/app_caller.py | 86 +++++++++++++++---- .../bin/xml/app_modules/app/config/config.py | 4 + src/scielo/bin/xml/run_app.py | 35 ++++++-- 4 files changed, 118 insertions(+), 51 deletions(-) diff --git a/src/scielo/bin/xml/app_modules/__init__.py b/src/scielo/bin/xml/app_modules/__init__.py index 8899b3b80..2fa0b10b8 100644 --- a/src/scielo/bin/xml/app_modules/__init__.py +++ b/src/scielo/bin/xml/app_modules/__init__.py @@ -1,29 +1,29 @@ # coding=utf-8 import os -try: - from app_modules.app.config import app_texts -except Exception as e: - print(e) - from .app.config import app_texts - -try: - from app_modules.app.config import app_caller -except Exception as e: - print(e) - from .app.config import app_caller try: - from app_modules.generics import logger -except Exception as e: - print(e) - from .generics import logger + from app_modules.app.config import ( + app_texts, + app_caller, + ) + from app_modules.generics import ( + logger, + encoding, + system, + ) -try: - from app_modules.generics import encoding except Exception as e: print(e) - from .generics import encoding + from .app.config import ( + app_texts, + app_caller, + ) + from .generics import ( + logger, + encoding, + system, + ) THIS_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__)).replace('\\', '/') @@ -31,7 +31,7 @@ INVALID_APP_PATH = not str(THIS_LOCATION) == THIS_FILE_LOCATION -BIN_PATH = THIS_LOCATION + '/../..' +BIN_PATH = os.path.dirname(os.path.dirname(THIS_LOCATION)) BIN_XML_PATH = BIN_PATH + '/xml' JAR_PATH = BIN_PATH + '/jar' RELATIVE_JAR_PATH = JAR_PATH.replace(BIN_PATH, './..') @@ -66,9 +66,3 @@ os.unlink(LOG_PATH+'/app_caller.log') except: pass - - -appcaller = app_caller.AppCaller( - logger.get_logger(LOG_PATH+'/app_caller.log', 'Environment'), - VENV_PATH, - REQUIREMENTS_FILE) diff --git a/src/scielo/bin/xml/app_modules/app/config/app_caller.py b/src/scielo/bin/xml/app_modules/app/config/app_caller.py index 1841fe477..69f2ff0b5 100644 --- a/src/scielo/bin/xml/app_modules/app/config/app_caller.py +++ b/src/scielo/bin/xml/app_modules/app/config/app_caller.py @@ -66,11 +66,11 @@ def register_commands(self): class VirtualEnv(object): - def __init__(self, logger, venv_path, requirements_filename): + def __init__(self, logger, venv_path, requirements_filename, proxy_data): self.logger = logger self.path = venv_path self.requirements = Requirements(requirements_filename) - self.proxy = ProxyInfo(None) + self.proxy = ProxyInfo(proxy_data) self.setUp() def setUp(self): @@ -153,6 +153,27 @@ def deactivate(self): system.run_command(self.deactivate_command, True) +class RealEnv(object): + + def __init__(self, logger, requirements_filename, proxy_data): + self.logger = logger + self.requirements = Requirements(requirements_filename) + self.proxy = ProxyInfo(proxy_data) + + def install_requirements(self): + commands = self.requirements.install_commands( + self.proxy, + uninstall=True) + self.execute_commands(commands) + + def execute_commands(self, commands): + for cmd in commands: + display_cmd = self.proxy.hide_password(cmd) + self.logger.info(display_cmd) + encoding.display_message(display_cmd) + system.run_command(cmd, False) + + class Requirements(object): def __init__(self, requirements_file): @@ -179,30 +200,59 @@ def uninstall_commands(self): return commands -class AppCaller(object): +class VEnvAppCaller(object): - def __init__(self, logger, venv_path, req_file): - self.venv = VirtualEnv(logger, venv_path, req_file) - - @property - def proxy(self): - return self.venv.proxy - - @proxy.setter - def proxy(self, value): - self.venv.proxy = ProxyInfo(value) + def __init__(self, logger, venv_path, req_file, proxy_data): + self.environment = VirtualEnv(logger, venv_path, req_file, proxy_data) def install_virtualenv(self, recreate=False): inform('Install virtualenv') - self.venv.install_venv() - if self.venv.installed: + self.environment.install_venv() + if self.environment.installed: inform('Install virtualenv: done!') def install_requirements(self): - if self.venv.installed: + if self.environment.installed: inform('Install Requirements') - self.venv.install_requirements() + self.environment.install_requirements() #inform('Install Requirements: done!') def execute(self, commands): - self.venv.execute_in_virtualenv(commands) + self.environment.execute_in_virtualenv(commands) + + +class RealAppCaller(object): + + def __init__(self, logger, venv_path, req_file, proxy_data): + self.environment = RealEnv(logger, req_file, proxy_data) + + def install_virtualenv(self, recreate=False): + pass + + def install_requirements(self): + self.environment.install_requirements() + + def execute(self, commands): + self.environment.execute_commands(commands) + + +class AppCaller(object): + + def __init__(self, logger, venv_path, req_file, proxy_data): + self.caller = None + if venv_path is not None: + virtual = VEnvAppCaller(logger, venv_path, req_file, proxy_data) + virtual.install_virtualenv(True) + if virtual.environment.installed: + self.caller = virtual + if self.caller is None: + self.caller = RealAppCaller(logger, venv_path, req_file, proxy_data) + + def install_virtualenv(self, recreate=False): + self.caller.install_virtualenv(recreate) + + def install_requirements(self): + self.caller.install_requirements() + + def execute(self, commands): + self.caller.execute(commands) diff --git a/src/scielo/bin/xml/app_modules/app/config/config.py b/src/scielo/bin/xml/app_modules/app/config/config.py index afbe4ed63..dd1306714 100644 --- a/src/scielo/bin/xml/app_modules/app/config/config.py +++ b/src/scielo/bin/xml/app_modules/app/config/config.py @@ -454,5 +454,9 @@ def coded_table_required(self): def BLOCK_DISAGREEMENT_WITH_COLLECTION_CRITERIA(self): return self.is_activated('BLOCK_DISAGREEMENT_WITH_COLLECTION_CRITERIA') + @property + def USE_VIRTUAL_ENV(self): + return self.is_activated('USE_VIRTUAL_ENV') + def is_activated(self, label, default='TRUE'): return self._data.get(label, default).upper() in ['ON', 'TRUE', 'YES'] diff --git a/src/scielo/bin/xml/run_app.py b/src/scielo/bin/xml/run_app.py index e49ba5f83..c9b2098fd 100644 --- a/src/scielo/bin/xml/run_app.py +++ b/src/scielo/bin/xml/run_app.py @@ -1,10 +1,29 @@ import sys -from app_modules.generics import encoding -from app_modules.generics import system -from app_modules.__init__ import appcaller -from app_modules.__init__ import BIN_XML_PATH -from app_modules.app.config import config +from app_modules.generics import ( + encoding, + system, + logger, +) +from app_modules.app.config import ( + app_caller, + config, +) +from app_modules.__init__ import ( + BIN_XML_PATH, + LOG_PATH, + VENV_PATH, + REQUIREMENTS_FILE, +) + +configuration = config.Configuration() + +appcaller = app_caller.AppCaller( + logger.get_logger(LOG_PATH+'/app_caller.log', 'Environment'), + VENV_PATH if configuration.USE_VIRTUAL_ENV is True else None, + REQUIREMENTS_FILE, + configuration.proxy_info +) def execute(parameters): @@ -46,9 +65,9 @@ def main(parameters): from app_modules.app import xc xc.call_converter(argv, '1.1') elif parameters[1] == 'install': - configuration = config.Configuration() - proxy_info = configuration.proxy_info - appcaller.proxy = system.proxy_data(proxy_info) + # configuration = config.Configuration() + # proxy_info = configuration.proxy_info + # appcaller.proxy = system.proxy_data(proxy_info) appcaller.install_virtualenv(True) appcaller.install_requirements() else: From 43522762dee7f0e4271e0653176aee3457270342 Mon Sep 17 00:00:00 2001 From: robertatakenaka Date: Fri, 20 Apr 2018 17:49:56 -0300 Subject: [PATCH 3/3] 40095_install_requirements --- .../xml/app_modules/app/config/app_caller.py | 72 +++++++++++++------ .../bin/xml/app_modules/generics/system.py | 2 +- src/scielo/bin/xml/run_app.py | 8 ++- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/scielo/bin/xml/app_modules/app/config/app_caller.py b/src/scielo/bin/xml/app_modules/app/config/app_caller.py index 69f2ff0b5..cab6e59f2 100644 --- a/src/scielo/bin/xml/app_modules/app/config/app_caller.py +++ b/src/scielo/bin/xml/app_modules/app/config/app_caller.py @@ -66,11 +66,11 @@ def register_commands(self): class VirtualEnv(object): - def __init__(self, logger, venv_path, requirements_filename, proxy_data): + def __init__(self, logger, venv_path, requirements_filename): self.logger = logger self.path = venv_path self.requirements = Requirements(requirements_filename) - self.proxy = ProxyInfo(proxy_data) + self.proxy_info = ProxyInfo(None) self.setUp() def setUp(self): @@ -99,17 +99,21 @@ def install_venv(self): if self.path is not None: if not self.installed: commands = [] - commands.extend(self.proxy.register_commands) + commands.extend(self.proxy_info.register_commands) + commands.append( + 'python -m pip install {} -U pip'.format( + self.proxy_info.parameter) + ) commands.append( 'python -m pip install {} --upgrade pip'.format( - self.proxy.parameter) + self.proxy_info.parameter) ) commands.append( - 'pip install {} virtualenv'.format(self.proxy.parameter) + 'pip install {} virtualenv'.format(self.proxy_info.parameter) ) commands.append(u'virtualenv "{}"'.format(self.path)) for cmd in commands: - if 'teste' in self.proxy.parameter: + if 'teste' in self.proxy_info.parameter: encoding.display_message('Executaria\n {}'.format(cmd)) else: system.run_command(cmd) @@ -122,7 +126,7 @@ def install_venv(self): def install_requirements(self): commands = self.requirements.install_commands( - self.proxy, + self.proxy_info, uninstall=True) self.execute_in_virtualenv(commands) @@ -136,7 +140,7 @@ def execute_in_virtualenv(self, commands): def _execute_inline(self, commands): _commands = [item for item in commands if len(item) > 0] cmd = self.sep.join(_commands) - display_cmd = self.proxy.hide_password(cmd) + display_cmd = self.proxy_info.hide_password(cmd) self.logger.info(display_cmd) if 'teste' in cmd: encoding.display_message('Executaria\n {}'.format(cmd)) @@ -155,23 +159,23 @@ def deactivate(self): class RealEnv(object): - def __init__(self, logger, requirements_filename, proxy_data): + def __init__(self, logger, requirements_filename): self.logger = logger self.requirements = Requirements(requirements_filename) - self.proxy = ProxyInfo(proxy_data) + self.proxy_info = ProxyInfo(None) def install_requirements(self): commands = self.requirements.install_commands( - self.proxy, + self.proxy_info, uninstall=True) self.execute_commands(commands) def execute_commands(self, commands): for cmd in commands: - display_cmd = self.proxy.hide_password(cmd) + display_cmd = self.proxy_info.hide_password(cmd) self.logger.info(display_cmd) encoding.display_message(display_cmd) - system.run_command(cmd, False) + os.system(cmd) class Requirements(object): @@ -184,6 +188,10 @@ def install_commands(self, proxy, uninstall): if uninstall is True: commands = self.uninstall_commands() commands.extend(proxy.register_commands) + commands.append( + 'python -m pip install {} -U pip'.format( + proxy.parameter) + ) commands.append( 'python -m pip install {} --upgrade pip'.format( proxy.parameter) @@ -202,8 +210,16 @@ def uninstall_commands(self): class VEnvAppCaller(object): - def __init__(self, logger, venv_path, req_file, proxy_data): - self.environment = VirtualEnv(logger, venv_path, req_file, proxy_data) + def __init__(self, logger, venv_path, req_file): + self.environment = VirtualEnv(logger, venv_path, req_file) + + @property + def proxy_info(self): + return self.environment.proxy_info + + @proxy_info.setter + def proxy_info(self, _proxy_info): + self.environment.proxy_info = _proxy_info def install_virtualenv(self, recreate=False): inform('Install virtualenv') @@ -223,8 +239,16 @@ def execute(self, commands): class RealAppCaller(object): - def __init__(self, logger, venv_path, req_file, proxy_data): - self.environment = RealEnv(logger, req_file, proxy_data) + def __init__(self, logger, venv_path, req_file): + self.environment = RealEnv(logger, req_file) + + @property + def proxy_info(self): + return self.environment.proxy_info + + @proxy_info.setter + def proxy_info(self, _proxy_info): + self.environment.proxy_info = _proxy_info def install_virtualenv(self, recreate=False): pass @@ -238,15 +262,23 @@ def execute(self, commands): class AppCaller(object): - def __init__(self, logger, venv_path, req_file, proxy_data): + def __init__(self, logger, venv_path, req_file): self.caller = None if venv_path is not None: - virtual = VEnvAppCaller(logger, venv_path, req_file, proxy_data) + virtual = VEnvAppCaller(logger, venv_path, req_file) virtual.install_virtualenv(True) if virtual.environment.installed: self.caller = virtual if self.caller is None: - self.caller = RealAppCaller(logger, venv_path, req_file, proxy_data) + self.caller = RealAppCaller(logger, venv_path, req_file) + + @property + def proxy_data(self): + return self.caller.proxy_info + + @proxy_data.setter + def proxy_data(self, _proxy_data): + self.caller.proxy_info = ProxyInfo(_proxy_data) def install_virtualenv(self, recreate=False): self.caller.install_virtualenv(recreate) diff --git a/src/scielo/bin/xml/app_modules/generics/system.py b/src/scielo/bin/xml/app_modules/generics/system.py index 25e2d87b9..055851266 100644 --- a/src/scielo/bin/xml/app_modules/generics/system.py +++ b/src/scielo/bin/xml/app_modules/generics/system.py @@ -90,5 +90,5 @@ def command_proxy_parameter(command): def proxy_password(param): if ':' in param and '@' in param: p = param[param.find(':'):] - p = p[:p.find('@')+1] + p = p[:p.rfind('@')+1] return p diff --git a/src/scielo/bin/xml/run_app.py b/src/scielo/bin/xml/run_app.py index c9b2098fd..83f21f8e1 100644 --- a/src/scielo/bin/xml/run_app.py +++ b/src/scielo/bin/xml/run_app.py @@ -16,13 +16,15 @@ REQUIREMENTS_FILE, ) + configuration = config.Configuration() +# proxy_data = system.proxy_data(configuration.proxy_info) + appcaller = app_caller.AppCaller( logger.get_logger(LOG_PATH+'/app_caller.log', 'Environment'), VENV_PATH if configuration.USE_VIRTUAL_ENV is True else None, - REQUIREMENTS_FILE, - configuration.proxy_info + REQUIREMENTS_FILE ) @@ -67,7 +69,7 @@ def main(parameters): elif parameters[1] == 'install': # configuration = config.Configuration() # proxy_info = configuration.proxy_info - # appcaller.proxy = system.proxy_data(proxy_info) + appcaller.proxy_data = system.proxy_data(configuration.proxy_info) appcaller.install_virtualenv(True) appcaller.install_requirements() else: