Alon Bar-Lev has uploaded a new change for review. Change subject: core: chdir('/') during install ......................................................................
core: chdir('/') during install Avoid errors from programs that do not know to run from removed directory. Change-Id: I467c3a8eaadf88f5060a96eefefd1872519cb32f Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M README.API M README.environment M src/otopi/__main__.py M src/otopi/constants.py M src/otopi/context.py M src/otopi/plugin.py M src/plugins/otopi/core/log.py M src/plugins/otopi/dialog/cli.py 8 files changed, 38 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/74/11274/1 diff --git a/README.API b/README.API index 9b41794..9b2d6ea 100644 --- a/README.API +++ b/README.API @@ -29,6 +29,10 @@ Plugins are loaded per python module, using the createPlugins() method. +Please notice that installer change working directory to '/', +every file that is being access that has the potential to be +relative should be resolved using plugin.resolveFile() function. + NOTICE: Boot exceptions (ImportError and such) are not printed, in order to see then set OTOPI_DEBUG=1 environment before running the script. diff --git a/README.environment b/README.environment index e19e52b..cdb5057 100644 --- a/README.environment +++ b/README.environment @@ -42,6 +42,10 @@ BASE/error(bool) Error during sequence. +BASE/executionDirectory(str) + Directory where instaler was executed. + Installer changes to '/' to avoid errors during program execution. + BASE/pluginGroups(str) Plugin groups to load. ':' separated. diff --git a/src/otopi/__main__.py b/src/otopi/__main__.py index cef86d2..991fab9 100644 --- a/src/otopi/__main__.py +++ b/src/otopi/__main__.py @@ -44,6 +44,8 @@ def _setupEnvironment(self, environment): """Setup environment based on command-line parameters.""" + environment[constants.BaseEnv.EXECUTION_DIRECTORY] = os.getcwd() + for arg in sys.argv[1:]: for statement in shlex.split(arg): entry = statement.split('=', 1) @@ -73,7 +75,13 @@ try: installer = main.Otopi() self._setupEnvironment(installer.environment) + os.chdir('/') installer.execute() + os.chdir( + installer.environment[ + constants.BaseEnv.EXECUTION_DIRECTORY + ] + ) return True except main.PluginLoadException as e: print( diff --git a/src/otopi/constants.py b/src/otopi/constants.py index ca05e60..8dbc36a 100644 --- a/src/otopi/constants.py +++ b/src/otopi/constants.py @@ -88,6 +88,7 @@ PLUGIN_PATH = 'BASE/pluginPath' PLUGIN_GROUPS = 'BASE/pluginGroups' DEBUG = 'BASE/debug' + EXECUTION_DIRECTORY = 'BASE/executionDirectory' COMMAND_PREFIX = 'COMMAND/' diff --git a/src/otopi/context.py b/src/otopi/context.py index 6552666..740381e 100644 --- a/src/otopi/context.py +++ b/src/otopi/context.py @@ -75,6 +75,8 @@ os.path.isdir(f) ) + plugindir = self.resolveFile(plugindir) + for group in _fulldir(plugindir): if _candidate(group): groupname = os.path.basename(group) @@ -318,6 +320,18 @@ else: raise RuntimeError(_('Error during sequence')) + def resolveFile(self, file): + """Resolve file based on installer execution directory""" + if os.path.isabs(file): + return file + else: + return os.path.join( + self.environment[ + constants.BaseEnv.EXECUTION_DIRECTORY + ], + file + ) + def dumpSequence(self): """Dump sequence.""" self.logger.debug('SEQUENCE DUMP - BEGIN') diff --git a/src/otopi/plugin.py b/src/otopi/plugin.py index 472116f..01fc303 100644 --- a/src/otopi/plugin.py +++ b/src/otopi/plugin.py @@ -295,6 +295,9 @@ self._context = context context.registerPlugin(self) + def resolveFile(self, file): + return self.context.resolveFile(file) + def executeRaw( self, args, diff --git a/src/plugins/otopi/core/log.py b/src/plugins/otopi/core/log.py index f94ff23..4ccea3b 100644 --- a/src/plugins/otopi/core/log.py +++ b/src/plugins/otopi/core/log.py @@ -132,7 +132,7 @@ os.environ[constants.SystemEnvironment.LOG_FILE] = logFileName self.environment[constants.CoreEnv.LOG_FILE_HANDLE] = open( - logFileName, + self.resolveFile(logFileName), mode='a', buffering=1 ) diff --git a/src/plugins/otopi/dialog/cli.py b/src/plugins/otopi/dialog/cli.py index 71586a8..b7fc99e 100644 --- a/src/plugins/otopi/dialog/cli.py +++ b/src/plugins/otopi/dialog/cli.py @@ -424,7 +424,9 @@ self.logger.error(_("Syntax error")) else: with open( - self.environment[constants.CoreEnv.LOG_FILE_NAME], + self.resolveFile( + self.environment[constants.CoreEnv.LOG_FILE_NAME] + ), 'r' ) as f: log = [ -- To view, visit http://gerrit.ovirt.org/11274 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I467c3a8eaadf88f5060a96eefefd1872519cb32f Gerrit-PatchSet: 1 Gerrit-Project: otopi Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches