提交 441772b8 编写于 作者: A Alessio Sergi

Better code organization

上级 79ec0cbe
......@@ -16,16 +16,37 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Init the Glances software
"""
__appname__ = 'glances'
__version__ = '2.0_RC4'
__author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPL'
# Import system lib
import gettext
import locale
import signal
import sys
# Import psutil
try:
from psutil import __version__ as __psutil_version
except ImportError:
print('psutil library not found. Glances cannot start.')
sys.exit(1)
# Check psutil version
psutil_min_version = (2, 0, 0)
psutil_version = tuple([int(num) for num in __psutil_version.split('.')])
if psutil_version < psutil_min_version:
print('psutil version {0} detected.').format(__psutil_version)
print('psutil 2.0 or higher is needed. Glances cannot start.')
sys.exit(1)
# Import Glances libs
# Note: others Glances libs will be imported optionally
from glances.core.glances_globals import gettext_domain, locale_dir
......
......@@ -30,7 +30,7 @@ except ImportError: # Python 2
from xmlrpclib import ServerProxy, ProtocolError
# Import Glances libs
from glances.core.glances_globals import __version__
from glances.core.glances_globals import version
from glances.core.glances_stats import GlancesStatsClient
from glances.outputs.glances_curses import glancesCurses
......@@ -102,7 +102,7 @@ class GlancesClient():
print(_("Error: Connection to server failed: {0}").format(err))
sys.exit(2)
if self.get_mode() == 'glances' and __version__[:3] == client_version[:3]:
if self.get_mode() == 'glances' and version[:3] == client_version[:3]:
# Init stats
self.stats = GlancesStatsClient()
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
......
......@@ -29,7 +29,7 @@ except ImportError: # Python 2
# Import Glances lib
from glances.core.glances_globals import (
__appname__,
appname,
is_bsd,
is_linux,
is_mac,
......@@ -101,20 +101,20 @@ class Config(object):
if is_linux or is_bsd:
paths.append(os.path.join(
os.environ.get('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
__appname__, self.config_filename))
appname, self.config_filename))
if hasattr(sys, 'real_prefix') or is_bsd:
paths.append(os.path.join(sys.prefix, 'etc', __appname__, self.config_filename))
paths.append(os.path.join(sys.prefix, 'etc', appname, self.config_filename))
else:
paths.append(os.path.join('/etc', __appname__, self.config_filename))
paths.append(os.path.join('/etc', appname, self.config_filename))
elif is_mac:
paths.append(os.path.join(
os.path.expanduser('~/Library/Application Support/'),
__appname__, self.config_filename))
appname, self.config_filename))
paths.append(os.path.join(
sys_prefix, 'etc', __appname__, self.config_filename))
sys_prefix, 'etc', appname, self.config_filename))
elif is_windows:
paths.append(os.path.join(
os.environ.get('APPDATA'), __appname__, self.config_filename))
os.environ.get('APPDATA'), appname, self.config_filename))
return paths
......
......@@ -17,30 +17,13 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Glances informations
__appname__ = 'glances'
__version__ = '2.0_RC4'
__author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPL'
# Import system libs
import os
import sys
# Import psutil
try:
from psutil import __version__ as __psutil_version__
except ImportError:
print('psutil library not found. Glances cannot start.')
sys.exit(1)
# Check psutil version
psutil_min_version = (2, 0, 0)
psutil_version = tuple([int(num) for num in __psutil_version__.split('.')])
if psutil_version < psutil_min_version:
print('psutil version {0} detected.').format(__psutil_version__)
print('psutil 2.0 or higher is needed. Glances cannot start.')
sys.exit(1)
# Global information
appname = 'glances'
version = __import__('glances').__version__
psutil_version = __import__('glances').__psutil_version
# PY3?
is_py3 = sys.version_info >= (3, 3)
......@@ -63,7 +46,7 @@ sys_path = sys.path[:]
sys.path.insert(0, plugins_path)
# i18n
gettext_domain = __appname__
gettext_domain = appname
i18n_path = os.path.realpath(os.path.join(work_path, '..', '..', 'i18n'))
sys_i18n_path = os.path.join(sys_prefix, 'share', 'locale')
if os.path.exists(i18n_path):
......@@ -73,8 +56,8 @@ elif os.path.exists(sys_i18n_path):
else:
locale_dir = None
# Instances shared between all Glances' scripts
# ===============================================
# Instances shared between all Glances scripts
# ============================================
# glances_processes for processcount and processlist plugins
from glances.core.glances_processes import glancesProcesses
......
......@@ -26,9 +26,9 @@ import argparse
# Import Glances libs
from glances.core.glances_config import Config
from glances.core.glances_globals import (
__appname__,
__psutil_version__,
__version__
appname,
psutil_version,
version
)
......@@ -58,9 +58,9 @@ class GlancesMain(object):
def init_args(self):
"""Init all the command line arguments."""
version = "Glances v" + __version__ + " with psutil v" + __psutil_version__
parser = argparse.ArgumentParser(prog=__appname__, conflict_handler='resolve')
parser.add_argument('-V', '--version', action='version', version=version)
_version = "Glances v" + version + " with psutil v" + psutil_version
parser = argparse.ArgumentParser(prog=appname, conflict_handler='resolve')
parser.add_argument('-V', '--version', action='version', version=_version)
parser.add_argument('-b', '--byte', action='store_true', default=False,
dest='byte', help=_('display network rate in byte per second'))
parser.add_argument('-B', '--bind', default='0.0.0.0', dest='bind_address',
......
......@@ -26,7 +26,7 @@ import uuid
# Import Glances lib
from glances.core.glances_globals import (
__appname__,
appname,
is_bsd,
is_linux,
is_mac,
......@@ -67,7 +67,7 @@ class glancesPassword:
app_path = '.'
# Append the Glances folder
app_path = os.path.join(app_path, __appname__)
app_path = os.path.join(app_path, appname)
return app_path
......
......@@ -30,7 +30,7 @@ except ImportError: # Python 2
from SimpleXMLRPCServer import SimpleXMLRPCServer
# Import Glances libs
from glances.core.glances_globals import __version__
from glances.core.glances_globals import version
from glances.core.glances_stats import GlancesStatsServer
from glances.core.glances_timer import Timer
......@@ -145,7 +145,7 @@ class GlancesInstance():
def init(self):
# Return the Glances version
return __version__
return version
def getAll(self):
# Update and return all the stats
......
......@@ -23,9 +23,9 @@ Just a stupid plugin to display the help screen
# Import Glances libs
from glances.core.glances_globals import (
__appname__,
__psutil_version__,
__version__
appname,
psutil_version,
version
)
from glances.plugins.glances_plugin import GlancesPlugin
......@@ -63,9 +63,9 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = '{0} {1}'.format(__appname__.title(), __version__)
msg = '{0} {1}'.format(appname.title(), version)
ret.append(self.curse_add_line(msg, "TITLE"))
msg = _(" with psutil {0}").format(__psutil_version__)
msg = _(" with psutil {0}").format(psutil_version)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_new_line())
......
......@@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from psutil import __version__ as __psutil_version__
from psutil import __version__ as __psutil_version
from glances.plugins.glances_plugin import GlancesPlugin
......@@ -52,7 +52,7 @@ class Plugin(GlancesPlugin):
if self.get_input() == 'local':
# PsUtil version only available in local
try:
self.stats = tuple([int(num) for num in __psutil_version__.split('.')])
self.stats = tuple([int(num) for num in __psutil_version.split('.')])
except NameError:
pass
else:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册