From dca0a64947dd2fdc4e523ff9f5c44b2314d39cb5 Mon Sep 17 00:00:00 2001 From: lihan Date: Thu, 29 Mar 2018 17:45:54 +0800 Subject: [PATCH 1/2] add system wide condig path --- qcloudcli/handleCmd.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qcloudcli/handleCmd.py b/qcloudcli/handleCmd.py index 22c6164..2d7cd7a 100644 --- a/qcloudcli/handleCmd.py +++ b/qcloudcli/handleCmd.py @@ -82,6 +82,12 @@ def showQcloudConfigurePath(self): sysHomePath = os.environ['HOME'] pass qcloudConfigurePath = os.path.join(sysHomePath, configurePathName) + if os.path.isdir(qcloudConfigurePath): + return qcloudConfigurePath + if 'Windows' not in platform.system(): + systemWideConfigurePath = '/etc/qcloudcli' + if os.path.isdir(systemWideConfigurePath): + return systemWideConfigurePath return qcloudConfigurePath def getAllmodules(self): From e3b5c249036337b4fec24d45ec173debcdb96b8c Mon Sep 17 00:00:00 2001 From: lihan Date: Thu, 29 Mar 2018 18:14:01 +0800 Subject: [PATCH 2/2] fix config path --- qcloudcli/configure.py | 23 +++++++++++++++++++---- qcloudcli/handleCmd.py | 16 +--------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/qcloudcli/configure.py b/qcloudcli/configure.py index 7d784cd..a9a31b5 100644 --- a/qcloudcli/configure.py +++ b/qcloudcli/configure.py @@ -27,10 +27,25 @@ def __init__(self, configWriter=None): self.home = ".qcloudcli" self.configure = "configure" self.credentials = "credentials" - self.qcloudConfigurePath = os.path.join(self.findConfigureFilePath(), - self.home) self.parser = handleParameter.handleParameter() + def showQcloudConfigurePath(self): + configurePathName = ".qcloudcli" + sysHomePath = '' + if 'Windows' in platform.system(): + sysHomePath = os.environ['HOMEPATH'] + else: + sysHomePath = os.environ['HOME'] + pass + qcloudConfigurePath = os.path.join(sysHomePath, configurePathName) + if os.path.isdir(qcloudConfigurePath): + return qcloudConfigurePath + if 'Windows' not in platform.system(): + systemWideConfigurePath = '/etc/qcloudcli' + if os.path.isdir(systemWideConfigurePath): + return systemWideConfigurePath + return qcloudConfigurePath + def getConfig(self, profilename=None): if profilename is None: profilename = 'default' @@ -63,10 +78,10 @@ def _getConfigFromFile(self, config, profile, filename): j = j+1 def getConfigFileName(self): - return os.path.join(self.qcloudConfigurePath, self.configure) + return os.path.join(self.showQcloudConfigurePath(), self.configure) def getCredsFileName(self): - return os.path.join(self.qcloudConfigurePath, self.credentials) + return os.path.join(self.showQcloudConfigurePath(), self.credentials) def findConfigureFilePath(self): homePath = "" diff --git a/qcloudcli/handleCmd.py b/qcloudcli/handleCmd.py index 2d7cd7a..95b1ab8 100644 --- a/qcloudcli/handleCmd.py +++ b/qcloudcli/handleCmd.py @@ -74,21 +74,7 @@ def showQcloudCliHelp(self): "know the module corresponding actions." % (self.red, self.end)) def showQcloudConfigurePath(self): - configurePathName = ".qcloudcli" - sysHomePath = '' - if 'Windows' in platform.system(): - sysHomePath = os.environ['HOMEPATH'] - else: - sysHomePath = os.environ['HOME'] - pass - qcloudConfigurePath = os.path.join(sysHomePath, configurePathName) - if os.path.isdir(qcloudConfigurePath): - return qcloudConfigurePath - if 'Windows' not in platform.system(): - systemWideConfigurePath = '/etc/qcloudcli' - if os.path.isdir(systemWideConfigurePath): - return systemWideConfigurePath - return qcloudConfigurePath + return self.globalConfigure.showQcloudConfigurePath() def getAllmodules(self): site_packages_path = get_python_lib()