diff --git a/gui/Footer.py b/gui/Footer.py
index 90b8303..87ddf72 100644
--- a/gui/Footer.py
+++ b/gui/Footer.py
@@ -102,7 +102,7 @@ def __init__(self, parent, gui_settings=None):
self.layout().addWidget(self.twitter_button, 0, 9, 3, 1)
#
footer_version_code = "v{0[0]}.{0[1]}.{0[2]}"
- farseer_version = footer_version_code.format(system.farseer_version)
+ farseer_version = footer_version_code.format(system.software_version)
version = '{} '.format(farseer_version)
diff --git a/install/commons.py b/install/commons.py
index 11d326c..84302bc 100644
--- a/install/commons.py
+++ b/install/commons.py
@@ -1,11 +1,17 @@
-# -*- coding: utf-8 -*-
"""
-COMMON FUNCTIONS TO FARSEER-NMR INSTALLATION AND UPDATE ROUTINES.
+Commons fuctions that serve installation and update.
Copyright © 2017-2019 Farseer-NMR Project
-Find us at:
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
- J. BioMol NMR Publication:
https://link.springer.com/article/10.1007/s10858-018-0182-5
@@ -46,6 +52,7 @@
from install import logger
from install import system
from install import messages
+from install import executables
log = logger.InstallLogger(__name__).gen_logger()
@@ -69,7 +76,7 @@
log.info(messages.something_wrong)
log.info(messages.additional_help)
log.info(messages.abort)
- user_input("Press ENTER to Terminate")
+ user_input(messages.terminate)
sys.exit(1)
@@ -284,16 +291,16 @@ def sub_call(exec_line):
return proc
-def create_executables(installation_folder, env_exec):
+def create_executables(installation_folder, python_exec):
"""
- Creates Farseer-NMR executables based on install.system lib.
+ Creates executables based on user.executables module.
Parameters:
- - installation_folder (str): the Farseer-NMR installation folder,
+ - installation_folder (str): the software installation folder,
where the 'bin' folder will reside
- - env_exec (str): the full path for the python executable
+ - python_exec (str): the full path for the python executable
"""
log.info(messages.gen_files_msg_head)
@@ -306,22 +313,16 @@ def create_executables(installation_folder, env_exec):
else:
log.debug("'bin' folder already existed")
- log.debug(": {}".format(env_exec))
-
- dict_of_execs = {
- 'gui': (system.gui_file, system.run_gui),
- 'cmd': (system.cmd_file, system.run_cmd),
- 'updater': (system.update_file, system.update_script)
- }
+ log.debug(": {}".format(python_exec))
- for key, executable in dict_of_execs.items():
+ for exec_name, code in executables.executable_files.items():
- exec_file = os.path.join(bin_folder, executable[0])
+ exec_file = os.path.join(bin_folder, exec_name)
fout = open(exec_file, 'w')
log.debug("opened {}".format(exec_file))
- fout.write(executable[1].format(env_exec))
+ fout.write(code.format(python_exec))
fout.close()
change_permissions_777(exec_file)
@@ -333,9 +334,10 @@ def create_executables(installation_folder, env_exec):
def register_install_vars(
install_dir,
- env_exec=None,
+ python_exec=None,
install_option=None,
conda_exec=None,
+ env_file=None,
env_name=None,
env_version=None,
miniconda_folder=None
@@ -344,16 +346,16 @@ def register_install_vars(
Writes installation variables to .py file.
"""
- install_reg_name = os.path.join(install_dir, 'install_reg.py')
+ install_reg_name = os.path.join(install_dir, 'installation_vars.py')
fout = open(install_reg_name, 'w')
log.debug("install_reg.py openned: {}".format(install_reg_name))
- install_register = """
+ installation_vars = """
# This file registers the installation variables
-# which are required for update purposes.
+# which are required for debugging and updating purposes.
#
-# Please do not delete it from the Farseer-NMR folder
+# Please do not delete it from the installation folder
#
# For additional help, please write us at:
# {}
@@ -361,26 +363,28 @@ def register_install_vars(
from pathlib import Path
install_option = {}
-install_wd = Path(r'{}')
+install_dir = Path(r'{}')
conda_exec = {}
python_exec = {}
miniconda_folder = {}
-farseer_env_name = {}
-farseer_env_version = {}
+installed_env_file = {}
+installed_env_name = {}
+installed_env_version = {}
""".format(
- messages.maillist_mail,
+ messages.mailist,
install_option,
install_dir,
"Path(r'{}')".format(conda_exec) if conda_exec else None,
- "Path(r'{}')".format(env_exec) if env_exec else None,
+ "Path(r'{}')".format(python_exec) if python_exec else None,
"Path(r'{}')".format(miniconda_folder) if miniconda_folder else None,
+ "Path(r'{}')".format(env_file) if env_file else None,
"'{}'".format(env_name) if env_name else None,
env_version
)
- log.debug(install_register)
+ log.debug(installation_vars)
- fout.write(install_register)
+ fout.write(installation_vars)
fout.close()
log.debug("install_reg created")
@@ -388,6 +392,6 @@ def register_install_vars(
def sys_exit(number=1):
- user_input("Press ENTER to TERMINATE")
+ user_input(messages.terminate)
sys.exit(number)
return
diff --git a/install/miniconder.py b/install/condamanager.py
similarity index 88%
rename from install/miniconder.py
rename to install/condamanager.py
index ab1aa3e..744c249 100644
--- a/install/miniconder.py
+++ b/install/condamanager.py
@@ -1,11 +1,18 @@
# -*- coding: utf-8 -*-
"""
-A MODULE TO MANAGE FARSEER-NMR PYTHON DEPENDENCIES VIA MINICONDA.
+Manages Miniconda and ENV installation.
Copyright © 2017-2019 Farseer-NMR Project
-Find us at:
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
- J. BioMol NMR Publication:
https://link.springer.com/article/10.1007/s10858-018-0182-5
@@ -59,16 +66,18 @@
class CondaManager():
"""
- Manages Miniconda installation and ENV configuration for
- Farseer-NMR.
+ Manages Miniconda installation and ENV configuration.
"""
- def __init__(self, cwd=None):
+ def __init__(self, cwd=None, env=None):
"""
Parameters:
- cwd (opt, str): the Miniconda installation path.
Defaults to os.get_cwd()
+
+ - env (opt): a YML env file. If None provided, can't install
+ environment.
"""
self.log = logger.InstallLogger(__name__).gen_logger()
@@ -103,13 +112,11 @@ def __init__(self, cwd=None):
self.set_miniconda_install_folder(
os.path.join(
self.get_install_folder(),
- system.miniconda_folder
+ system.default_miniconda_folder
)
)
- self.set_env_file(system.latest_env_file)
-
- self.set_env_version(system.latest_env_version)
+ self.set_env_file(env)
return
@@ -199,13 +206,21 @@ def set_miniconda_install_folder(self, folder):
def set_env_file(self, env_file):
"""
- Sets Miniconda Farseer-NMR environment file.
+ Sets Miniconda environment file for host project.
Parameters:
- env_file (str): path to Anaconda Env (.yml) file.
"""
+ if env_file is None:
+ self._env_file = None
+ self.log.debug(": ".format(self._env_file))
+ self.set_env_name(None)
+ self.set_env_version(None)
+
+ return
+
self.log.debug("reading env_file: {}".format(env_file))
valid_file = bool(
@@ -271,9 +286,9 @@ def set_conda_exec(self, conda_exec):
return
- def set_env_name(self, name='farseernmr'):
+ def set_env_name(self, name='treeoflife'):
"""
- Sets Farseer-NMR Conda environment name.
+ Sets Conda environment name.
"""
self._env_name = name
@@ -282,7 +297,7 @@ def set_env_name(self, name='farseernmr'):
def set_env_python_exec(self, python_exec):
"""
- Defines Python executable for Farseer-NMR environment.
+ Defines Python executable for host project.
"""
self._env_python_exec = python_exec
@@ -293,14 +308,21 @@ def set_env_python_exec(self, python_exec):
def set_env_version(self, env_version):
"""
- Sets Farsee-NMR Miniconda environment version.
+ Sets Miniconda environment version.
Should be integer.
"""
try:
int(env_version)
+
+ except TypeError as e:
+ self._env_version = None
+ self.log.debug(e)
+ self.log.debug(": None")
+ return
+
except ValueError as e:
self.log.info(
- "* ERROR * Farseer-NMR Python environment version"
+ "* ERROR * Python environment version"
"should be integer type"
)
self.log.info("* ERROR * env version not set")
@@ -375,7 +397,7 @@ def get_env_folder(self):
def check_previous_miniconda_folder(self, folder='[M|m]iniconda.*'):
"""
Checks if a Miniconda related folder exists inside
- the Farseer-NMR folder. Accepts regex.
+ the host project installation folder. Accepts regex.
Returns folder name, False otherwise.
"""
@@ -472,7 +494,7 @@ def install_miniconda(self):
# installs miniconda
commons.sub_call(exec_line)
- # sets miniconda conda exec file
+ # sets miniconda conda and python exec files
if system.platform in ("Windows"):
# https://stackoverflow.com/questions/37117571/where-does-anaconda-python-install-on-windows
# https://stackoverflow.com/questions/44597662/conda-command-is-not-recognized-on-windows-10
@@ -484,6 +506,13 @@ def install_miniconda(self):
'conda.exe'
)
)
+
+ self.set_env_python_exec(
+ os.path.join(
+ self.get_miniconda_install_folder(),
+ 'python.exe'
+ )
+ )
else: # UNIX systems
self.set_conda_exec(
@@ -493,6 +522,14 @@ def install_miniconda(self):
'conda'
)
)
+
+ self.set_env_python_exec(
+ os.path.join(
+ self.get_miniconda_install_folder(),
+ 'bin',
+ 'python'
+ )
+ )
return
@@ -549,6 +586,10 @@ def install_env(self):
Installs Anaconda Environment.
"""
+ if self.get_env_name() is None:
+ self.log.debug("no environment to install... ignoring...")
+ return
+
self.log.info("* Starts Miniconda Environment Installation")
# defines command to create environment from .yml file
@@ -595,8 +636,13 @@ def install_env(self):
def logs_env_information(self):
"""
- Register installed env to log file.
+ Registers installed env to log file.
"""
+
+ if self.get_env_name() is None:
+ self.log.debug("no environment to install... ignoring...")
+ return
+
self.log.info("* Registering environment...")
# confirm environment was installed correctly
@@ -614,7 +660,7 @@ def logs_env_information(self):
def add_install_folder_to_site_packages(self):
"""
- Adds Farseer-NMR directory to Miniconda Farseer-NMR environment.
+ Adds the host project directory to the Miniconda environment.
"""
# https://stackoverflow.com/questions/37006114/anaconda-permanently-include-external-packages-like-in-pythonpath
@@ -634,7 +680,7 @@ def add_install_folder_to_site_packages(self):
result = commons.sub_call(exec_line).decode("utf-8").split('\n')
self.log.debug("\n".join(result))
- self.log.debug("Farseer-NMR folder added to site-packges")
+ self.log.debug("Host project folder added to site-packges")
return
@@ -642,6 +688,11 @@ def remove_env(self):
"""
Removes Miniconda Environment.
"""
+
+ if self.get_env_name() is None:
+ self.log.debug("no environment to remove... ignoring...")
+ return
+
self.log.info("* Removing Miniconda Environment")
exec_line = '{} remove -vy --name {} --all'.format(
@@ -656,4 +707,4 @@ def remove_env(self):
if __name__ == "__main__":
- print('I am Miniconder')
+ print('I am Tree-of-Life')
diff --git a/install/executables.py b/install/executables.py
new file mode 100644
index 0000000..64b63bc
--- /dev/null
+++ b/install/executables.py
@@ -0,0 +1,311 @@
+"""
+Defines Farseer-NMR Executables
+
+Copyright © 2017-2019 Farseer-NMR Project
+
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
+- J. BioMol NMR Publication:
+ https://link.springer.com/article/10.1007/s10858-018-0182-5
+
+- GitHub: https://github.com/Farseer-NMR
+
+- Mail list: https://groups.google.com/forum/#!forum/farseer-nmr
+ email: farseer-nmr@googlegroups.com
+
+- Research Gate: https://goo.gl/z8dPJU
+
+- Twitter: https://twitter.com/farseer_nmr
+
+THIS FILE IS PART OF THE FARSEER-NMR PROJECT.
+
+Contributors to this file:
+- João M.C. Teixeira (https://github.com/joaomcteixeira)
+
+Farseer-NMR is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Farseer-NMR is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Farseer-NMR. If not, see .
+"""
+
+from install import system
+
+# interesting readings:
+# https://stackoverflow.com/questions/6943208/activate-a-virtualenv-with-a-python-script
+# https://halotis.com/running-python-code-in-windows-batch-file-trick/
+# https://docs.python.org/3.3/using/windows.html
+# finally, shebangs can be used on Windows10
+# allow double click execution
+
+# define your executable scripts
+run_cmd_code = r"""#! {}
+'''
+Executes Farseer-NMR command line.
+REQUIRES PYTHON 3
+Read further at:
+https://github.com/Farseer-NMR/FarSeer-NMR/wiki/Documentation#running-command-line
+usage:
+ farseer_cmd CONFIG.JSON [opt, PATH TO SPECTRA FOLDER]
+
+ - PATH TO SPECTRA FOLDER, folder where 'spectra' folder resides
+example:
+ farseer_cmd my_config.json
+ farseer_cwd my_config.json .
+
+'''
+import sys
+import os
+
+farseernmr_folder = os.path.abspath(
+ os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ os.pardir
+ )
+ )
+
+sys.path.append(farseernmr_folder)
+
+if sys.version_info[0] != 3:
+ sys.stderr.write("Python 3 is required to run Farseer-NMR")
+ sys.exit(1)
+
+import core.farseermain
+
+if len(sys.argv) == 2:
+ farseer = core.farseermain.FarseerNMR(sys.argv[1])
+
+elif len(sys.argv) == 3:
+ farseer = core.farseermain.FarseerNMR(
+ sys.argv[1],
+ spectra_folder_path=sys.argv[2]
+ )
+else:
+ sys.stderr.write(__doc__)
+ sys.exit(1)
+
+farseer.run()
+"""
+
+run_gui_code = r"""#! {}
+import sys
+import os
+
+farseernmr_folder = os.path.abspath(
+ os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ os.pardir
+ )
+ )
+
+sys.path.append(farseernmr_folder)
+
+if sys.version_info[0] != 3:
+ sys.stderr.write("Python 3 is required to run Farseer-NMR")
+ sys.exit(1)
+
+import gui.main
+
+gui.main.run(sys.argv)
+"""
+
+update_script_code = r"""#! {}
+
+import sys
+import os
+import importlib
+import pathlib
+
+software_folder = os.path.abspath(
+ os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ os.pardir
+ )
+ )
+
+sys.path.append(software_folder)
+
+if sys.version_info[0] != 3:
+ sys.stderr.write("Python 3 is required to run Updater")
+ sys.exit(1)
+
+from install import logger
+from install import messages
+from install import system
+from install import executables
+
+try:
+ import installation_vars
+except ModuleNotFoundError as e:
+ print(e)
+ print("* ERROR * installation_vars.py file not found")
+ print("* ERROR * this file has created during installation")
+ print("* ERROR * and is required for UPDATING")
+ print("* ERROR * Reinstall the SOFTWARE to repair updating functions")
+ print(messages.additional_help)
+ print(messages.abort)
+ input(messages.terminate)
+ sys.exit(1)
+
+try:
+ install_dir = installation_vars.install_dir
+ python_exec = installation_vars.python_exec
+ install_option = installation_vars.install_option
+ conda_exec = installation_vars.conda_exec
+ installed_env_file = installation_vars.installed_env_file
+ installed_env_name = installation_vars.installed_env_name
+ installed_env_version = installation_vars.installed_env_version
+ miniconda_folder = installation_vars.miniconda_folder
+
+except AttributeError as e:
+ print(messages.update_var_missing)
+ print()
+ print(messages.consider_reinstall)
+ print(messages.additional_help)
+ print(e)
+ print(messages.abort)
+ input(messages.terminate)
+ sys.exit(1)
+
+list_of_paths = [
+ install_dir,
+ python_exec,
+ conda_exec,
+ miniconda_folder,
+ miniconda_folder
+ ]
+
+for _path in list_of_paths:
+ if isinstance(_path, pathlib.Path) and not _path.exists():
+ print(messages.update_var_missing)
+ print(os.fspath(_path) + " path does NOT exists")
+ print()
+ print()
+ print(messages.consider_reinstall)
+ print(messages.additional_help)
+ print(messages.abort)
+ input(messages.terminate)
+ sys.exit(1)
+
+update_log = install_dir.joinpath(system.update_log_name)
+
+if update_log.exists():
+ update_log.unlink()
+
+log = logger.InstallLogger(__name__, log_file_name=update_log).gen_logger()
+
+log.debug("start updating")
+
+from install import updater
+from install import commons
+from install import condamanager
+
+upf = updater.Updater(install_dir)
+upf.run()
+
+# reloads the libs updated version
+importlib.reload(system)
+importlib.reload(executables)
+
+log.info("* Checking Conda environment...")
+
+if install_option == 1:
+
+ if system.latest_env_version > installed_env_version:
+
+ log.info("* A NEW Python environment version is available")
+ log.info("* Software's dependencies must be updated")
+
+ if os.path.exists(conda_exec):
+
+ log.info("* Miniconda installation found")
+ log.info(" ... starting env update")
+
+ upc = condamanager.CondaManager(cwd=install_dir)
+ upc.set_conda_exec(conda_exec)
+ upc.set_env_name(installed_env_name)
+ upc.remove_env()
+ upc.set_env_file(system.latest_env_file)
+ upc.install_env()
+ upc.logs_env_information()
+ log.info("... Conda env UPDATED")
+
+ # registers installation variables
+ install_option = 1
+ conda_exec = upc.get_conda_exec()
+ python_exec = upc.get_env_python_exec()
+ installed_env_file = upc.get_env_file()
+ installed_env_name = upc.get_env_name()
+ installed_env_version = upc.get_env_version()
+ miniconda_folder = upc.get_miniconda_install_folder()
+
+ else:
+ log.info("* ERROR * Could not find the CONDA executable")
+ log.info(messages.something_wrong)
+ log.info(messages.additional_help)
+ log.info(messages.update_continues)
+ log.info(messages.consider_reinstall)
+ else:
+ log.info(" ...Conda env already in latest version")
+ log.info("")
+
+elif install_option == 2:
+ log.info(
+ "* You have previously configured Python libraries manually.\n"
+ "* Please check if it's necessary to update the software's \n"
+ "* Python dependencies, consult .yml file in 'install' folder."
+ )
+
+else:
+ log.info("* ERROR* We couldn't access install information")
+ log.info(messages.something_wrong)
+ log.info(messages.additional_help)
+ log.info(messages.consider_reinstall)
+ log.info(messages.abort)
+ sys.exit(1)
+
+log.info("* Updating executable files...")
+
+commons.create_executables(install_dir, python_exec)
+
+commons.register_install_vars(
+ install_dir=install_dir,
+ python_exec=python_exec,
+ install_option=install_option,
+ conda_exec=conda_exec,
+ env_file=installed_env_file,
+ env_name=installed_env_name,
+ env_version=installed_env_version,
+ miniconda_folder=miniconda_folder
+ )
+
+log.info(messages.update_completed)
+commons.sys_exit()
+"""
+
+# executable scripts file names and extensions
+run_cmd = "farseer_cmd{}".format(system.exec_file_extension)
+run_gui = "farseer_gui{}".format(system.exec_file_extension)
+updatescript = "farseer_update{}".format(system.exec_file_extension)
+
+# dictionary listing the executable scripts
+# keys are file names, values the string with code
+executable_files = {
+ run_cmd: run_cmd_code,
+ run_gui: run_gui_code,
+ updatescript: update_script_code
+ }
diff --git a/install/logger.py b/install/logger.py
index 2cc828a..fcb833c 100644
--- a/install/logger.py
+++ b/install/logger.py
@@ -1,11 +1,18 @@
# -*- coding: utf-8 -*-
"""
-LOGGER MODULE.
+Logger module.
Copyright © 2017-2019 Farseer-NMR Project
-Find us at:
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
- J. BioMol NMR Publication:
https://link.springer.com/article/10.1007/s10858-018-0182-5
@@ -42,7 +49,7 @@
class InstallLogger():
- log_file_name = 'log.log'
+ log_file_name = 'farseernmr.log'
def __init__(self, name, log_file_name=None):
"""
diff --git a/install/messages.py b/install/messages.py
index 2d163d5..0cc1bd0 100644
--- a/install/messages.py
+++ b/install/messages.py
@@ -1,11 +1,17 @@
-# -*- coding: utf-8 -*-
"""
-INFORMATIVE MESSAGES FOR FARSEER-NMR INSTALLATION AND UPDATE.
+Informative messages for the installation and update processes.
Copyright © 2017-2019 Farseer-NMR Project
-Find us at:
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
- J. BioMol NMR Publication:
https://link.springer.com/article/10.1007/s10858-018-0182-5
@@ -40,10 +46,11 @@
import textwrap
from install import system
+from install import executables
-install_wiki = "https://github.com/Farseer-NMR/FarSeer-NMR/wiki/Download,-Install-and-Update"
-windows_wiki = "https://github.com/Farseer-NMR/FarSeer-NMR/wiki/Documentation#running-on-windows"
-maillist_mail = "farseer-nmr@googlegroups.com"
+# provide a link and e-mail with further documentation on the install process
+install_wiki = "https://github.com/Farseer-NMR/FarSeer-NMR/wiki"
+mailist = "farseer-nmr@googlegroups.com"
# configure textwrapper
@@ -53,7 +60,7 @@
tw.drop_whitespace = True
tw.initial_indent = "* "
tw.subsequent_indent = "* "
-tw.width=70
+tw.width = 70
def _formats_message_body(s):
@@ -65,12 +72,12 @@ def _formats_message_body(s):
[tw.fill(line) for line in s.splitlines() if line.strip() != '']
)
- return body+"\n"
+ return body + "\n"
def _formats_main_title(s):
- star = 72*'*'
+ star = 72 * '*'
title = "*** {: ^64} ***".format(s.upper())
return "{}\n{}\n{}\n".format(star, title, star)
@@ -82,8 +89,8 @@ def _formats_short_title(s):
s = " {} ".format(s.upper())
return "{:*^72}\n".format(s)
-# GENERAL
+# GENERAL MESSAGES
query = "-> provide a valid option: "
big_query = """
@@ -91,56 +98,36 @@ def _formats_short_title(s):
- Type any '{}' to abort
""".format(", ".join(system.deny))
-gen_files_msg_head = \
- _formats_main_title("Generated Farseer-NMR executable files")
-
-gen_files_msg_tail = _formats_message_body("""
-Three executable files were generated inside the Farseer-NMR installation folder:
-{} <- runs GUI interface (recommended)
-{} <- runs command line (advanced)
-{} <- updates Farseer-NMR
-""".format(
- os.path.join('bin', system.gui_file),
- os.path.join('bin', system.cmd_file),
- os.path.join('bin', system.update_file)
- )
- )
-
-_windows_advice = \
-"""
-Farseer-NMR is EXPECTED to work on Windows machines tough, support for Windows is limited.
+gen_files_msg_head = _formats_main_title("Generated executable files")
-You are advised to read the additional instructions on HOW TO run Farseer-NMR on windows before proceeding,
-please visit:
-"""
+list_of_files = ""
+for file_ in executables.executable_files.keys():
+ list_of_files += "-> {}\n".format(os.path.join('bin', file_))
-windows_additional_support = (
- _formats_short_title("WINDOWS USERS") +
- _formats_message_body(_windows_advice) +
- "* {}\n".format(windows_wiki) +
- _formats_message_body("Thank you :-)") +
- 72*'*'+"\n"
+gen_files_msg_tail = _formats_message_body(
+ "Executable files were generated inside the installation folder:\n"
+ + list_of_files
)
-_install_perfect = \
-"""
-Farseer-NMR installation COMPLETED successfully
-Press ENTER to finish
+# SUCCESS MESSAGES
+
+_install_perfect = """
+The software installation COMPLETED successfully
"""
install_completed = (
- _formats_main_title("perfect") +
- _formats_message_body(_install_perfect)
+ _formats_main_title("perfect")
+ + _formats_message_body(_install_perfect)
)
# INSTALLATION
-start_install = _formats_message_body("Starting Installation of Farseer-NMR")
+start_install = _formats_message_body("Starting installation...")
install_header = (
- _formats_short_title("The required Python libraries must be installed") +
- _formats_message_body("Choose an installation option")
+ _formats_short_title("The required Python libraries must be installed")
+ + _formats_message_body("Choose an installation option")
)
install_options_full = """
@@ -152,49 +139,51 @@ def _formats_short_title(s):
# MINICONDA INSTALL
-_auto_install_message = """
-Miniconda (https://www.anaconda.com/) along with the Farseer-NMR Python dependencies will be installed in the Farseer-NMR folder where the install_farseernmr.py file resides.
-
-{}
-
-This Miniconda installation will serve ONLY Farseer-NMR, not interfeering with your system's Python installation.
-
-Miniconda will be installed in SILENT mode, without additional queries to the user. If you continue, you accept Anaconda License and Terms and Conditions.
-
-You can READ Anaconda Terms and Conditions in the link bellow:
-
-https://anaconda.org/about/legal/terms
-
-If you do NOT agree type 'exit', 'no', or 'abort' to abort installation.
-
-You can, instead, choose to install the required Python libraries manually and independently of the Anaconda distribution, just restart the installation process and choose install option [2].
-
-If you AGREE with Anaconda Terms just press ENTER to continue the installation.
-
-""".format(system.installation_folder)
+_auto_install_message = (
+ "Miniconda (https://www.anaconda.com/) along with the "
+ "Python dependencies will be installed in the following folder:\n"
+ "{}\n"
+ "This Miniconda installation will serve ONLY this folder "
+ "not interfeering with your system's Python installation.\n"
+ "\n"
+ "Miniconda will be installed in SILENT mode, "
+ "without additional queries to the user. If you continue, "
+ "you accept Anaconda License and Terms and Conditions."
+ "\n"
+ "You can READ Anaconda Terms and Conditions in the link bellow:\n"
+ "\n"
+ "https://anaconda.org/about/legal/terms\n"
+ "\n"
+ "If you do NOT agree type 'exit', 'no', or 'abort' to abort installation. "
+ "You can, instead, choose to install the required Python libraries "
+ "manually and independently of the Anaconda distribution, "
+ "just restart the installation process and choose install option [2].\n"
+ "If you AGREE with Anaconda Terms just press ENTER to continue "
+ "the installation.\n"
+ )
install_miniconda_terms_and_conditions = (
- _formats_short_title("NOTICE") +
- _formats_message_body(_auto_install_message)
+ _formats_short_title("NOTICE")
+ + _formats_message_body(_auto_install_message)
)
install_miniconda_proceed = _formats_message_body(
- "A dedicated Miniconda distribution for Farseer-NMR will be installed"
+ "A dedicated Miniconda distribution will be installed"
)
_query_miniconda_reinstall = """
-A Miniconda installation already exists in the Farseer-NMR folder.
-Do you want to reinstall Miniconda for Farseer-NMR?
+A Miniconda installation already exists in this folder.
+Do you want to reinstall Miniconda"?
If YES, the current Miniconda will be DELETED and a NEW one installed.
If NO, the installation will abort.
-[YES/no]:
+[YES/no]:
"""
query_miniconda_reinstall = (
- _formats_short_title("QUERY") +
- _formats_message_body(_query_miniconda_reinstall)
+ _formats_short_title("QUERY")
+ + _formats_message_body(_query_miniconda_reinstall)
)
reinstall_canceled = """
@@ -202,56 +191,86 @@ def _formats_short_title(s):
* Installation CANCELED
"""
-envs_okay = "* OK * The Farseer-NMR Anaconda Environment installed SUCCESSFULLY"
+envs_okay = "* OK * The Anaconda Environment installed SUCCESSFULLY"
# MANUAL INSTALL
-_manual_install = \
-"""
-You chose to configure Farseer-NMR installation manually, no Python libraries will be installed now.
+_manual_install = (
+ "You chose to configure {} manually, ".format(system.software_name)
+ + "no Python libraries will be installed now.\n"
+ "\n"
+ "We assume that you are a proficient Python user and "
+ "you can and want to READ, UNDERSTAND and INSTALL the "
+ "required dependencies on your own.\n"
+ "\n"
+ "You can check the required Python libraries in the '.yml' env file "
+ "inside the 'install' folder. Use this file to create your own "
+ "Anaconda environment if you use Anaconda or as a guide to know "
+ "which are the Python dependencies for {}.\n".format(system.software_name)
+ + "\n"
+ "The installer will now generate TEMPLATE executable files. You may "
+ "WISH or NEED to MODIFY {}'s".format(system.software_name)
+ + " executable files according to "
+ "your system's and Python preferences.\n"
+ "If you don't install the required Python libraries and don't correctly "
+ "configure the executable files, "
+ "{} MIGHT NOT WORK.".format(system.software_name)
+ )
-We assume that you are a proficient Python user and you can and want to READ, UNDERSTAND and INSTALL the required dependencies on your own.
+manual_install = (
+ _formats_short_title("notice")
+ + _formats_message_body(_manual_install)
+ )
-You can check the required Python libraries in the '.yml' env file inside the 'install' folder. Use this file to create your own Anaconda environment if you use Anaconda or as a guide to know which are the Python dependencies of Farseer-NMR.
+# UPDATER
-The installer will now generate TEMPLATE executable files. You may WISH or NEED to MODIFY the Farseer-NMR executable files according to your system's and Python preferences.
+update_var_missing = (
+ _formats_short_title("error")
+ + _formats_message_body(
+ "An installation variable necessary for UPDATING"
+ " is missing or broken in installation_vars.py"
+ )
+ )
-If you don't install the required Python libraries and don't correctly configure the executable files, Farseer-NMR MIGHT NOT WORK.
+update_continues = """
+* Despite the ERRORS the update will continue
"""
-manual_install = (
- _formats_short_title("notice") +
- _formats_message_body(_manual_install)
+consider_reinstall = (
+ _formats_short_title("notice")
+ + _formats_message_body(
+ "Something went wrong during the updating process. "
+ "The easiest method to solve this issue is to reinstall "
+ "the software."
+ )
)
-# UPDATER
-
-_update_perfect = \
-"""
-Farseer-NMR update COMPLETED successfully
+_update_perfect = """
+{} update COMPLETED successfully
Press ENTER to finish
-"""
+""".format(system.software_name)
update_completed = (
- _formats_main_title("perfect") +
- _formats_message_body(_update_perfect)
+ _formats_main_title("perfect")
+ + _formats_message_body(_update_perfect)
)
# HELP MESSAGES
-_add_help = \
-"""
-For additional help, please:
-- contact us via mailing list ({}) providing the .log file created during the installation/update process.
-
-- or check out our installation wiki page:
-""".format(maillist_mail)
+_add_help = (
+ "For additional help, please:\n"
+ "- contact us via mailing list ({}) ".format(mailist)
+ + "providing the .log file "
+ "created during the installation/update process.\n"
+ "- or check out our installation wiki page:\n"
+ "{}".format(install_wiki)
+ )
additional_help = (
- _formats_short_title("help") +
- _formats_message_body(_add_help) +
- "* {}\n".format(install_wiki) +
- 72*'*'+"\n"
+ _formats_short_title("help")
+ + _formats_message_body(_add_help)
+ + 72 * '*'
+ + "\n"
)
# ERRORS
@@ -276,7 +295,7 @@ def _formats_short_title(s):
"""
fs_env_failed = """
-* ERROR * The Farseer-NMR Anaconda Environment COULD NOT be installed.
+* ERROR * The Anaconda Environment COULD NOT be installed.
* ERROR * Check the following error mensage:
{}
@@ -295,13 +314,15 @@ def _formats_short_title(s):
* ERROR * and provide the log file created during the process
* ERROR * so that we can help you solve this problem
* ERROR * Thank you!
-""".format(maillist_mail)
+""".format(mailist)
abort = """
*** Aborting installation ***
"""
-# http://patorjk.com/software/taag/#p=display&h=1&f=Doom&t=---------%0AFarSeer-NMR%0Av1.3.0%0A---------
+terminate = "Press ENTER to TERMINATE"
+
+# http://patorjk.com/software/taag/#p=display&h=1&f=Sweet&t=Tree%20of%20Life
banner = r"""
@@ -319,12 +340,12 @@ def _formats_short_title(s):
\_| \__,_||_| \____/ \___| \___||_| \_| \_/\_| |_/\_| \_|
- __ _____ __
- / | |____ | / |
-__ __`| | / / `| |
-\ \ / / | | \ \ | |
- \ V / _| |_ _ .___/ /_ _| |_
- \_/ \___/(_)\____/(_)\___/
+ __ _____ _____
+ / | |____ | / __ \
+__ __`| | / / `' / /'
+\ \ / / | | \ \ / /
+ \ V / _| |_ _ .___/ /_ ./ /___
+ \_/ \___/(_)\____/(_)\_____/
@@ -342,7 +363,6 @@ def _formats_short_title(s):
print(big_query)
print(gen_files_msg_head)
print(gen_files_msg_tail)
- print(windows_additional_support)
print(install_completed)
print(start_install)
print(install_header)
@@ -353,7 +373,10 @@ def _formats_short_title(s):
print(reinstall_canceled)
print(envs_okay)
print(manual_install)
+ print(update_var_missing)
print(update_completed)
+ print(update_continues)
+ print(consider_reinstall)
print(additional_help)
print(not_enough_space)
print(unknown_python)
diff --git a/install/system.py b/install/system.py
index 767337d..9cb3f6f 100644
--- a/install/system.py
+++ b/install/system.py
@@ -1,11 +1,18 @@
"""
MANAGES SYSTEM INFORMATION AND OTHER NECESSARY PARAMETERS
- FOR FARSEER-NMR INSTALLATION AND UPDATE.
+ FOR INSTALLATION AND UPDATE.
Copyright © 2017-2019 Farseer-NMR Project
-Find us at:
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
- J. BioMol NMR Publication:
https://link.springer.com/article/10.1007/s10858-018-0182-5
@@ -36,47 +43,44 @@
You should have received a copy of the GNU General Public License
along with Farseer-NMR. If not, see .
"""
+
import platform as pltfrm
import os
-farseer_version = (1, 3, 1) # v1.3.0
+# configure accordingly to the host project
+software_name = "Farseer-NMR"
+software_version = (1, 3, 2) # v1.0.0
+min_space_allowed = 3 # min GB required to install your software
+installation_log_name = "install.log"
+update_log_name = "update.log"
+_lastest_env_file = "farseernmr.yml"
+_miniconda_folder = "miniconda"
-min_space_allowed = 3 # GB
+# about the default installation folder
+_file_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+installation_folder = os.path.abspath(os.path.join(_file_path, os.pardir))
+# about the running system
_platforms = {"Linux": "Linux", "Darwin": "MacOSX", "Windows": "Windows"}
-_executable_file_extensions = {"Linux": None, "MacOSX": None, "Windows": "py"}
+_executable_file_extensions = {"Linux": "", "MacOSX": "", "Windows": "py"}
platform = _platforms[pltfrm.system()]
bits = "x86_64" if (pltfrm.machine().endswith('64')) else "x86"
-
exec_file_extension = _executable_file_extensions[platform]
-approve = ["Y", "YES"]
-deny = ["N", "NO", "EXIT", "E", "A", "ABORT"]
-
-gui_file = 'farseer_gui'
-cmd_file = 'farseer_cmd'
-update_file = 'farseer_update'
-
-if exec_file_extension:
- gui_file += '.{}'.format(exec_file_extension)
- cmd_file += '.{}'.format(exec_file_extension)
- update_file += '.{}'.format(exec_file_extension)
-
-_file_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
-
-installation_folder = os.path.abspath(os.path.join(_file_path, os.pardir))
-
-latest_env_file = os.path.join(_file_path, 'farseernmr.yml')
+# about conda env
+latest_env_file = os.path.join(_file_path, _lastest_env_file)
+default_miniconda_folder = os.path.join(installation_folder, _miniconda_folder)
-with open(os.path.join(_file_path, latest_env_file)) as f:
+with open(latest_env_file, 'r') as f:
for line in f:
if line.startswith('name:'):
latest_env_name = line.strip().split()[-1]
elif line.startswith('# version:'):
latest_env_version = int(line.strip().split()[-1])
-miniconda_folder = 'miniconda'
+
+# about downloading Miniconda
base_miniconda_web_link = "https://repo.continuum.io/miniconda/"
_miniconda_file_extensions = {
"Linux": "sh",
@@ -85,198 +89,7 @@
}
miniconda_file_extension = _miniconda_file_extensions[platform]
-# https://stackoverflow.com/questions/6943208/activate-a-virtualenv-with-a-python-script
-# https://halotis.com/running-python-code-in-windows-batch-file-trick/
-# https://docs.python.org/3.3/using/windows.html
-# finally, shebangs can be used on Windows10
-# allow double click execution
-
-run_gui = """#! {}
-import sys
-import os
-
-farseernmr_folder = os.path.abspath(
- os.path.join(
- os.path.dirname(os.path.realpath(__file__)),
- os.pardir
- )
- )
-
-sys.path.append(farseernmr_folder)
-
-if sys.version_info[0] != 3:
- sys.stderr.write("Python 3 is required to run Farseer-NMR")
- sys.exit(1)
-
-import gui.main
-gui.main.run(sys.argv)
-"""
-
-run_cmd = """#! {}
-'''
-Executes Farseer-NMR command line.
-
-REQUIRES PYTHON 3
-
-Read further at:
-https://github.com/Farseer-NMR/FarSeer-NMR/wiki/Documentation#running-command-line
-
-usage:
- farseer_cmd CONFIG.JSON [opt, PATH TO SPECTRA FOLDER]
-
- - PATH TO SPECTRA FOLDER, folder where 'spectra' folder resides
-
-example:
- farseer_cmd my_config.json
- farseer_cwd my_config.json .
-
-'''
-import sys
-import os
-
-farseernmr_folder = os.path.abspath(
- os.path.join(
- os.path.dirname(os.path.realpath(__file__)),
- os.pardir
- )
- )
-sys.path.append(farseernmr_folder)
-
-if sys.version_info[0] != 3:
- sys.stderr.write("Python 3 is required to run Farseer-NMR")
- sys.exit(1)
-
-import core.farseermain
-
-if len(sys.argv) == 2:
- farseer = core.farseermain.FarseerNMR(sys.argv[1])
-elif len(sys.argv) == 3:
- farseer = core.farseermain.FarseerNMR(
- sys.argv[1],
- spectra_folder_path=sys.argv[2]
- )
-else:
- sys.stderr.write(__doc__)
- sys.exit(1)
-
-farseer.run()
-"""
-
-update_script = """#! {}
-
-import sys
-import os
-import importlib
-
-farseernmr_folder = os.path.abspath(
- os.path.join(
- os.path.dirname(os.path.realpath(__file__)),
- os.pardir
- )
- )
-
-sys.path.append(farseernmr_folder)
-
-if sys.version_info[0] != 3:
- sys.stderr.write("Python 3 is required to run Farseer-NMR")
- sys.exit(1)
-
-from install import logger
-from install import messages
-
-try:
- import install_reg
-except ModuleNotFoundError as e:
- print("* ERROR * install_reg.py file not found")
- print("* ERROR * this file has created during installation")
- print("* ERROR * and is required for UPDATING")
- print("* ERROR * Reinstall Farseer-NMR to repair updating functions")
- print(messages.additional_help)
- print(messages.abort)
- sys.exit(1)
-
-update_log = install_reg.install_wd.joinpath('update.log')
-
-if update_log.exists():
- update_log.unlink()
-
-log = logger.InstallLogger(__name__, log_file_name=update_log).gen_logger()
-
-log.debug("start updating")
-
-from install import updater
-from install import commons
-from install import miniconder
-
-upf = updater.FarseerUpdater(install_reg.install_wd)
-upf.run()
-
-# reloads the updated version of system lib
-from install import system
-importlib.reload(system)
-
-log.info("* Checking Conda environment...")
-
-env_exec_new = install_reg.python_exec
-install_option_new = install_reg.install_option
-
-if system.latest_env_version > install_reg.farseer_env_version:
-
- log.info("* A NEW Python environment version is available")
- log.info("* Farseer-NMR dependencies must be updated")
-
- if install_reg.conda_exec and install_reg.install_option == 1:
-
- log.info("* Miniconda installation found")
- log.info(" ... starting env update")
-
- upc = miniconder.CondaManager(cwd=install_reg.install_wd)
- upc.set_conda_exec(install_reg.conda_exec)
- upc.set_env_name(install_reg.farseer_env_name)
- upc.remove_env()
- upc.set_env_file(system.latest_env_file)
- upc.install_env()
- upc.logs_env_information()
- upc.add_install_folder_to_site_packages()
- log.info("... Conda env UPDATED")
-
- env_exec_new = upc.get_env_python_exec()
- install_option_new = 1
-
- elif not(install_reg.conda_exec) and install_reg.install_option == 2:
- log.info("* You have previously configured Python libraries mannually")
- log.info("* You should update Farseer-NMR Python dependencies")
- log.info("* consult .yml file in 'install' folder")
-
- else:
- log.info("* ERROR* We couldn't access install information")
- log.info(messages.something_wrong)
- log.info(messages.additional_help)
- log.info(messages.abort)
- sys.exit(1)
-
-else:
- log.info(" ...Conda env already in latest version")
- log.info("")
-
-log.info("* Updating executable files...")
-
-commons.create_executables(
- install_reg.install_wd,
- env_exec_new
- )
-
-commons.register_install_vars(
- install_reg.install_wd,
- env_exec=env_exec_new,
- install_option=install_option_new,
- conda_exec=install_reg.conda_exec,
- env_name=system.latest_env_name,
- env_version=system.latest_env_version,
- miniconda_folder=system.miniconda_folder
- )
-
-log.info(messages.update_completed)
-commons.sys_exit()
-"""
+# other variables
+approve = ["Y", "YES"]
+deny = ["N", "NO", "EXIT", "E", "A", "ABORT"]
diff --git a/install/updater.py b/install/updater.py
index ba1ab8b..037f12c 100644
--- a/install/updater.py
+++ b/install/updater.py
@@ -1,10 +1,17 @@
"""
-A MODULE TO MANAGE FARSEER-NMR UPDATE.
+Manages software updates.
Copyright © 2017-2019 Farseer-NMR Project
-Find us at:
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
- J. BioMol NMR Publication:
https://link.springer.com/article/10.1007/s10858-018-0182-5
@@ -46,8 +53,7 @@
if python_version != 3:
python_version_error = """
-Python 3 is required to run Farseer-NMR
- Press ENTER to terminate
+Python 3 is required. Press ENTER to terminate.
"""
user_input(python_version_error)
sys.exit(1)
@@ -61,15 +67,20 @@
from install import commons
from install import messages
+_new_version_url = \
+ "https://github.com/Farseer-NMR/FarSeer-NMR/archive/master.zip"
+_new_version_zip = "master.zip"
+_folders_to_remove = ["Documentation", "gui", "core", "install", ".idea"]
+
-class FarseerUpdater():
+class Updater():
"""
- Controls Farseer-NMR version Updating methods.
+ Controls version Updating methods.
Strategy:
- Downloads master branch from Farseer-NMR repository.
+ Downloads master branch .zip file from project repository.
Unzips.
- Removes old Farseer-NMR files and folders.
+ Removes old files and folders.
Replaces with new version files and folders.
Maintains install configuration, namely Miniconda installation
and Python executable paths on bin files.
@@ -79,19 +90,19 @@ def __init__(
self,
install_wd,
update_log="update.log",
- new_version_url="https://github.com/Farseer-NMR/FarSeer-NMR/archive/master.zip",
- new_version_zip="master.zip",
- folders_to_remove=["Documentation", "gui", "core", "install", ".idea"]
+ new_version_url=_new_version_url,
+ new_version_zip=_new_version_zip,
+ folders_to_remove=_folders_to_remove
):
"""
Parameters:
- - install_wd (str): the Farseer-NMR installation directory
+ - install_wd (str): the software installation directory
- update_log (opt): the name of the log file (df: 'update.log')
- new_version_url (opt): link to new version
- (df: https://github.com/Farseer-NMR/FarSeer-NMR/archive/master.zip)
+ (df: https://github.com//master.zip)
- new_version_zip (opt): ZIP file to temporarily save new version
(df: 'master.zip')
@@ -102,7 +113,7 @@ def __init__(
"""
self.log = logger.InstallLogger(__name__).gen_logger()
- self.log.debug("Initiated FarseerUpdater instance")
+ self.log.debug("Initiated Updater instance")
self.set_install_wd(install_wd)
@@ -114,17 +125,17 @@ def __init__(
return
def get_new_version_url(self):
- """Returns URL for Farseer-NMR new version."""
+ """Returns URL for the software new version."""
return self._new_version_url
def get_new_version_zip(self):
- """Returns name of ZIP file for Farseer-NMR new version."""
+ """Returns name of ZIP file for software's new version."""
return self._new_version_zip
def get_folders_to_remove(self):
"""
Returns list of old folders to remove
- when updating to Farseer-NMR new version.
+ when updating to software's new version.
"""
return self._folders_to_remove
@@ -139,7 +150,7 @@ def get_zip_folder(self):
def get_install_wd(self):
"""
- Returns Farseer-NMR installation directory to be updated
+ Returns software's installation directory to be updated
to the new version.
"""
return self._install_wd
@@ -165,7 +176,7 @@ def set_folders_to_remove(self, folders):
return
def set_install_wd(self, folder):
- """Sets Farseer-NMR installation (update) folder."""
+ """Sets software's installation (update) folder."""
if not os.path.exists(folder):
e = "* ERROR * Folder does not exist: '{}'".format(folder)
@@ -186,10 +197,10 @@ def set_zip_folder(self, zip_folder):
self.log.debug(": {}".format(zip_folder))
return
- def download_farseernmr(self):
- """Downloads the new version of Farseer-NMR."""
+ def download_software(self):
+ """Downloads the software's new version."""
- self.log.info("* Starting Farseer-NMR new version download.")
+ self.log.info("* Starting software's new version download.")
commons.download_file(
self.get_new_version_url(),
@@ -202,7 +213,7 @@ def download_farseernmr(self):
return
def remove_old_version(self):
- """Removes previous Farseer-NMR folders"""
+ """Removes previous software's folders"""
self.log.info("* Removing old folders...")
self.log.debug("install_wd: {}".format(self.get_install_wd()))
@@ -224,7 +235,7 @@ def remove_old_version(self):
def unzip_new_version(self):
"""Unzips new version"""
- # lists current files/folders in Farseer-NMR folder
+ # lists current files/folders in installation folder
previous_dirs = set(os.listdir(self.get_install_wd()))
self.log.debug(": {}".format("\n".join(previous_dirs)))
@@ -243,7 +254,7 @@ def unzip_new_version(self):
zip_ref.extractall(self.get_install_wd())
zip_ref.close()
- # lists files/folders in Farseer-NMR folder
+ # lists files/folders in installation folder
new_dirs = set(os.listdir(self.get_install_wd()))
self.log.debug(" set: {}".format("\n".join(new_dirs)))
@@ -277,7 +288,7 @@ def unzip_new_version(self):
def move_new_files(self):
"""
- Moves new files to Farseer-NMR installation directory.
+ Moves new files to software's installation directory.
"""
self.log.info("* Moving new files...")
@@ -367,13 +378,13 @@ def clean_files(self):
def run(self):
"""Runs standard update algorythm."""
- self.log.info("\n*** Starting Farseer-NMR update ***\n")
- self.download_farseernmr()
+ self.log.info("\n*** Starting update ***\n")
+ self.download_software()
self.unzip_new_version()
self.remove_old_version()
self.move_new_files()
self.clean_files()
- self.log.info("\n*** Farseer-NMR Update Completed ***\n")
+ self.log.info("\n*** Update Completed ***\n")
return
diff --git a/install_farseernmr.py b/install_farseernmr.py
index 4c73cb6..39d5bbd 100644
--- a/install_farseernmr.py
+++ b/install_farseernmr.py
@@ -1,11 +1,17 @@
-# -*- coding: utf-8 -*-
"""
-FARSEER-NMR INSTALLER.
+Farseer-NMR installer.
Copyright © 2017-2019 Farseer-NMR Project
-Find us at:
+THIS FILE WAS ADAPTED FROM TREE-OF-LIFE PROJECT (version 1.0.1 - LGPLv3)
+AND MODIFIED ACCORDINGLY TO THE NEEDS OF THE FARSEER-NMR PROJECT.
+Visit the original Tree-of-Life project at:
+
+https://github.com/joaomcteixeira/Tree-of-Life
+
+
+Find Farseer-NMR project at:
- J. BioMol NMR Publication:
https://link.springer.com/article/10.1007/s10858-018-0182-5
@@ -40,28 +46,28 @@
import os
import time # used to give a more human feeling to the install process
-installation_folder = \
- os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+libs_folder = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
# appends 'install' folder to allow lib import
-sys.path.append(os.path.join(installation_folder, "install"))
+sys.path.append(os.path.join(libs_folder, "install"))
+from install import system
+from install import messages
+# logging is required before importing the other package libs
from install import logger
-logfile_name = os.path.join(installation_folder, 'install.log')
+# STARTS LOGGING
+logfile_name = os.path.join(
+ system.installation_folder,
+ system.installation_log_name
+ )
if os.path.exists(logfile_name):
os.remove(logfile_name)
log = logger.InstallLogger(__name__, log_file_name=logfile_name).gen_logger()
-log.debug("install_farseernmr.py initiated")
-log.debug(": {}".format(installation_folder))
-
-from install import system
-from install import messages
-from install import commons
-from install import miniconder
+# CONFIRMS PYTHON VERSION
python_version = sys.version_info[0]
log.debug("* Python version: {}".format(python_version))
@@ -74,45 +80,57 @@
else:
log.info(messages.unknown_python)
log.info("* You are running Python version: {}".format(python_version))
- log.info("Farseer-NMR setup.py requires Python 2.7 or 3.x to execute")
+ _name = system.software_name
+ log.info("* {} requires Python 2.7 or 3.x to execute".format(_name))
log.info(messages.additional_help)
log.info(messages.abort)
- commons.sys_exit()
+ user_input(messages.terminate)
+ sys.exit(1)
-if installation_folder.find(" ") > 0:
- log.info(messages.path_with_spaces.format(installation_folder))
+if system.installation_folder.find(" ") > 0:
+ log.info(messages.path_with_spaces.format(system.installation_folder))
log.info(messages.additional_help)
log.info(messages.abort)
- commons.sys_exit()
+ user_input(messages.terminate)
+ sys.exit(1)
-# STARTS INSTALLATION
+# continues importing log dependent libs
+from install import commons
+from install import condamanager
+# STARTS INSTALLATION
+log.debug("{} installation initiated".format(system.software_name))
+log.debug(": {}".format(system.installation_folder))
log.info(messages.banner)
log.info(messages.start_install)
time.sleep(0.5)
-# Queries installation option
log.info(messages.install_header)
log.info(messages.install_options_full)
-choice = None
-while choice not in ("1", "2", "3"):
- choice = user_input(messages.query)
- log.debug("install_choice: {}".format(choice))
- if choice == "4":
+# Queries installation option
+install_choice = None
+while install_choice not in ("1", "2", "3"):
+ install_choice = user_input(messages.query).strip()
+ log.debug("install_choice: {}".format(install_choice))
+ if install_choice == "4":
log.info(messages.additional_help)
log.info(messages.install_options_full)
-log.debug("final install_choice: {}".format(choice))
+log.debug("final install_choice: {}".format(install_choice))
log.info("\n")
+
time.sleep(0.5)
# Applies choice
-if choice == "1": # installs Miniconda and Farseer-NMR Environment
+if install_choice == "1": # installs Miniconda and Python Environment
log.debug("entered install option 1")
- miniconda_handler = miniconder.CondaManager(cwd=installation_folder)
+ miniconda_handler = condamanager.CondaManager(
+ cwd=system.installation_folder,
+ env=system.latest_env_file
+ )
# returns name of folder, if found.
previous_miniconda_folder = \
@@ -132,7 +150,7 @@
choice = None
while not(choice in system.approve) and not(choice in system.deny):
- choice = user_input(messages.query).upper()
+ choice = user_input(messages.query).strip().upper()
log.debug(": {}".format(choice))
log.debug("Resinstall option chosen: {}".format(choice))
@@ -156,22 +174,22 @@
log.info(messages.install_miniconda_proceed)
- if not(commons.check_available_disk_space()): # requires 3GB minimum
+ if not(commons.check_available_disk_space()):
log.info(messages.not_enough_space)
log.info(messages.additional_help)
log.info(messages.abort)
commons.sys_exit()
# Queries user to agree with Anaconda Terms and Conditions
- log.info(messages.install_miniconda_terms_and_conditions)
+ mf = os.path.abspath(system.default_miniconda_folder)
+ log.info(messages.install_miniconda_terms_and_conditions.format(mf))
choice = 1
- while not(choice in system.approve) \
- and not(choice in system.deny) \
- and not(choice == ""):
-
- choice = user_input(messages.query).upper()
+ approve = system.approve + [""]
+
+ while choice not in approve and choice not in system.deny:
+ choice = user_input(messages.query).strip().upper()
- if choice in system.approve or choice == "":
+ if choice in approve:
log.info("continuing...")
elif choice in system.deny:
@@ -188,7 +206,10 @@
# registers installation variables
install_option = 1
conda_exec = miniconda_handler.get_conda_exec()
- env_exec = miniconda_handler.get_env_python_exec()
+ python_exec = miniconda_handler.get_env_python_exec()
+ env_file = miniconda_handler.get_env_file()
+ env_name = miniconda_handler.get_env_name()
+ env_version = miniconda_handler.get_env_version()
miniconda_folder = miniconda_handler.get_miniconda_install_folder()
# cleans
@@ -196,10 +217,10 @@
os.remove(miniconda_install_file)
log.debug("removed: {}".format(miniconda_install_file))
-elif choice == "2": # Manual Python libs installation
+elif install_choice == "2": # Manual Python libs installation
log.info(messages.manual_install)
- choice = user_input(messages.big_query).upper()
+ choice = user_input(messages.big_query).strip().upper()
if choice in system.deny:
log.info(messages.additional_help)
@@ -208,11 +229,14 @@
# registers installation variables
install_option = 2
- env_exec = sys.executable
+ python_exec = sys.executable
+ env_file = None
+ env_name = None
+ env_version = None
conda_exec = None
miniconda_folder = None
-elif choice == "3":
+elif install_choice == "3":
log.info(messages.additional_help)
log.info(messages.abort)
commons.sys_exit()
@@ -224,19 +248,20 @@
time.sleep(1)
-# creates Farseer-NMR executable files
-commons.create_executables(installation_folder, env_exec)
+# creates executable files
+commons.create_executables(system.installation_folder, python_exec)
# registers installation variables in a file.py
commons.register_install_vars(
- install_dir=installation_folder,
- env_exec=env_exec,
+ install_dir=system.installation_folder,
+ python_exec=python_exec,
install_option=install_option,
conda_exec=conda_exec,
- env_name=system.latest_env_name,
- env_version=system.latest_env_version,
+ env_file=env_file,
+ env_name=env_name,
+ env_version=env_version,
miniconda_folder=miniconda_folder
)
log.info(messages.install_completed)
-user_input()
+user_input(messages.terminate)