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 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..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 @@ -70,7 +70,7 @@ def __init__(self, logger, venv_path, requirements_filename): self.logger = logger self.path = venv_path self.requirements = Requirements(requirements_filename) - self.proxy = ProxyInfo(None) + 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)) @@ -153,6 +157,27 @@ def deactivate(self): system.run_command(self.deactivate_command, True) +class RealEnv(object): + + def __init__(self, logger, requirements_filename): + self.logger = logger + self.requirements = Requirements(requirements_filename) + self.proxy_info = ProxyInfo(None) + + def install_requirements(self): + commands = self.requirements.install_commands( + self.proxy_info, + uninstall=True) + self.execute_commands(commands) + + def execute_commands(self, commands): + for cmd in commands: + display_cmd = self.proxy_info.hide_password(cmd) + self.logger.info(display_cmd) + encoding.display_message(display_cmd) + os.system(cmd) + + class Requirements(object): def __init__(self, requirements_file): @@ -163,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) @@ -179,30 +208,83 @@ 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) + self.environment = VirtualEnv(logger, venv_path, req_file) @property - def proxy(self): - return self.venv.proxy + def proxy_info(self): + return self.environment.proxy_info - @proxy.setter - def proxy(self, value): - self.venv.proxy = ProxyInfo(value) + @proxy_info.setter + def proxy_info(self, _proxy_info): + self.environment.proxy_info = _proxy_info 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): + 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 + + 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): + self.caller = None + if venv_path is not None: + 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) + + @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) + + 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/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 e49ba5f83..83f21f8e1 100644 --- a/src/scielo/bin/xml/run_app.py +++ b/src/scielo/bin/xml/run_app.py @@ -1,10 +1,31 @@ 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() + +# 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 +) def execute(parameters): @@ -46,9 +67,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_data = system.proxy_data(configuration.proxy_info) appcaller.install_virtualenv(True) appcaller.install_requirements() else: