Miscellaneous fixes and improvements

Rules of thumb:
- setup.py only <=, >=
- requirements.txt only ==
This commit is contained in:
Alessio Sergi 2014-05-07 16:59:59 +02:00
parent 6fa10b5a2b
commit 3687321b30
10 changed files with 74 additions and 69 deletions

View File

@ -8,5 +8,6 @@ include glances/outputs/static/css/*.css
include glances/outputs/static/js/*.js include glances/outputs/static/js/*.js
include man/glances.1 include man/glances.1
recursive-include docs images/*.png glances-doc.html recursive-include docs images/*.png glances-doc.html
recursive-include glances *.py
recursive-include i18n *.mo recursive-include i18n *.mo
prune docs/_build prune docs/_build

View File

@ -21,11 +21,14 @@ Init the Glances software
""" """
# Import system lib # Import system lib
import gettext
import locale
import signal import signal
import sys import sys
# Import Glances libs # Import Glances libs
# Note: others Glances libs will be imported optionally # Note: others Glances libs will be imported optionally
from glances.core.glances_globals import gettext_domain, locale_dir
from glances.core.glances_main import GlancesMain from glances.core.glances_main import GlancesMain
@ -58,9 +61,13 @@ def end():
def main(): def main():
""" """
Main entry point for Glances Main entry point for Glances
Select the mode (standalone, client or server) Select the mode (standalone, client or server)
Run it... Run it...
""" """
# Setup translations
locale.setlocale(locale.LC_ALL, '')
gettext.install(gettext_domain, locale_dir)
# Share global var # Share global var
global core, standalone, client, server global core, standalone, client, server

View File

@ -30,11 +30,12 @@ except ImportError: # Python 2
# Import Glances lib # Import Glances lib
from glances.core.glances_globals import ( from glances.core.glances_globals import (
__appname__, __appname__,
is_BSD, is_bsd,
is_Linux, is_linux,
is_Mac, is_mac,
is_Windows, is_py3,
is_python3, is_windows,
sys_prefix,
work_path work_path
) )
@ -62,7 +63,7 @@ class Config(object):
for path in self.get_paths_list(): for path in self.get_paths_list():
if os.path.isfile(path) and os.path.getsize(path) > 0: if os.path.isfile(path) and os.path.getsize(path) > 0:
try: try:
if is_python3: if is_py3:
self.parser.read(path, encoding='utf-8') self.parser.read(path, encoding='utf-8')
else: else:
self.parser.read(path) self.parser.read(path)
@ -105,26 +106,23 @@ class Config(object):
if os.path.exists(conf_path): if os.path.exists(conf_path):
paths.append(os.path.join(conf_path, self.filename)) paths.append(os.path.join(conf_path, self.filename))
if is_Linux or is_BSD: if is_linux or is_bsd:
paths.append(os.path.join( paths.append(os.path.join(
os.environ.get('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'), os.environ.get('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
__appname__, self.filename)) __appname__, self.filename))
elif is_Mac: if is_linux:
paths.append(os.path.join('/etc', __appname__, self.filename))
else:
paths.append(os.path.join(sys.prefix, 'etc', __appname__, self.filename))
elif is_mac:
paths.append(os.path.join( paths.append(os.path.join(
os.path.expanduser('~/Library/Application Support/'), os.path.expanduser('~/Library/Application Support/'),
__appname__, self.filename)) __appname__, self.filename))
elif is_Windows:
paths.append(os.path.join(
os.environ.get('APPDATA'), __appname__, self.filename))
if is_Linux:
paths.append(os.path.join('/etc', __appname__, self.filename))
elif is_BSD:
paths.append(os.path.join(
sys.prefix, 'etc', __appname__, self.filename))
elif is_Mac:
paths.append(os.path.join( paths.append(os.path.join(
sys_prefix, 'etc', __appname__, self.filename)) sys_prefix, 'etc', __appname__, self.filename))
elif is_windows:
paths.append(os.path.join(
os.environ.get('APPDATA'), __appname__, self.filename))
return paths return paths

View File

@ -24,8 +24,6 @@ __author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPL' __license__ = 'LGPL'
# Import system libs # Import system libs
import gettext
import locale
import os import os
import sys import sys
@ -36,11 +34,9 @@ except ImportError:
print('psutil module not found. Glances cannot start.') print('psutil module not found. Glances cannot start.')
sys.exit(1) sys.exit(1)
# psutil version
psutil_version = tuple([int(num) for num in __psutil_version__.split('.')])
# Check psutil version # Check psutil version
psutil_min_version = (2, 0, 0) psutil_min_version = (2, 0, 0)
psutil_version = tuple([int(num) for num in __psutil_version__.split('.')])
if psutil_version < psutil_min_version: if psutil_version < psutil_min_version:
print('psutil version %s detected.' % __psutil_version__) print('psutil version %s detected.' % __psutil_version__)
print('psutil 2.0 or higher is needed. Glances cannot start.') print('psutil 2.0 or higher is needed. Glances cannot start.')
@ -51,20 +47,18 @@ work_path = os.path.realpath(os.path.dirname(__file__))
appname_path = os.path.split(sys.argv[0])[0] appname_path = os.path.split(sys.argv[0])[0]
sys_prefix = os.path.realpath(os.path.dirname(appname_path)) sys_prefix = os.path.realpath(os.path.dirname(appname_path))
# Is this Python 3? # PY3?
is_python3 = sys.version_info >= (3, 2) is_py3 = sys.version_info >= (3, 2)
# Operating system flag # Operating system flag
# Note: Somes libs depends of OS # Note: Somes libs depends of OS
is_BSD = sys.platform.find('bsd') != -1 is_bsd = sys.platform.find('bsd') != -1
is_Linux = sys.platform.startswith('linux') is_linux = sys.platform.startswith('linux')
is_Mac = sys.platform.startswith('darwin') is_mac = sys.platform.startswith('darwin')
is_Windows = sys.platform.startswith('win') is_windows = sys.platform.startswith('win')
# i18n # i18n
locale.setlocale(locale.LC_ALL, '') gettext_domain = __appname__
gettext_domain = 'glances'
# get locale directory
i18n_path = os.path.realpath(os.path.join(work_path, '..', '..', 'i18n')) i18n_path = os.path.realpath(os.path.join(work_path, '..', '..', 'i18n'))
sys_i18n_path = os.path.join(sys_prefix, 'share', 'locale') sys_i18n_path = os.path.join(sys_prefix, 'share', 'locale')
if os.path.exists(i18n_path): if os.path.exists(i18n_path):
@ -73,7 +67,6 @@ elif os.path.exists(sys_i18n_path):
locale_dir = sys_i18n_path locale_dir = sys_i18n_path
else: else:
locale_dir = None locale_dir = None
gettext.install(gettext_domain, locale_dir)
# Instances shared between all Glances' scripts # Instances shared between all Glances' scripts
# =============================================== # ===============================================

View File

@ -20,7 +20,7 @@
import psutil import psutil
# Import Glances lib # Import Glances lib
from glances.core.glances_globals import is_BSD, is_Mac, is_Windows from glances.core.glances_globals import is_bsd, is_mac, is_windows
from glances.core.glances_timer import Timer, getTimeSinceLastUpdate from glances.core.glances_timer import Timer, getTimeSinceLastUpdate
@ -130,7 +130,7 @@ class glancesProcesses:
# If io_tag = 0 > Access denied (display "?") # If io_tag = 0 > Access denied (display "?")
# If io_tag = 1 > No access denied (display the IO rate) # If io_tag = 1 > No access denied (display the IO rate)
# Note Disk IO stat not available on Mac OS # Note Disk IO stat not available on Mac OS
if not is_Mac: if not is_mac:
try: try:
# Get the process IO counters # Get the process IO counters
proc_io = proc.io_counters() proc_io = proc.io_counters()
@ -182,9 +182,9 @@ class glancesProcesses:
# ignore the 'idle' process on Windows and *BSD # ignore the 'idle' process on Windows and *BSD
# ignore the 'kernel_task' process on OS X # ignore the 'kernel_task' process on OS X
# waiting for upstream patch from psutil # waiting for upstream patch from psutil
if (is_BSD and procstat['name'] == 'idle' or if (is_bsd and procstat['name'] == 'idle' or
is_Windows and procstat['name'] == 'System Idle Process' or is_windows and procstat['name'] == 'System Idle Process' or
is_Mac and procstat['name'] == 'kernel_task'): is_mac and procstat['name'] == 'kernel_task'):
continue continue
# Update processcount (global statistics) # Update processcount (global statistics)
try: try:

View File

@ -21,11 +21,11 @@
import sys import sys
# Import Glances lib # Import Glances lib
from glances.core.glances_globals import glances_logs, glances_processes, is_Windows from glances.core.glances_globals import glances_logs, glances_processes, is_windows
from glances.core.glances_timer import Timer from glances.core.glances_timer import Timer
# Import curses lib for "normal" operating system and consolelog for Windows # Import curses lib for "normal" operating system and consolelog for Windows
if not is_Windows: if not is_windows:
try: try:
import curses import curses
import curses.panel import curses.panel

View File

@ -90,7 +90,7 @@ class Plugin(GlancesPlugin):
msg = "{0:8}".format(_("LOAD")) msg = "{0:8}".format(_("LOAD"))
ret.append(self.curse_add_line(msg, "TITLE")) ret.append(self.curse_add_line(msg, "TITLE"))
# Core number # Core number
msg = "{0:>6}".format(str(self.core_plugin.update()["log"])+_("core")) msg = "{0:>6}".format(str(self.core_plugin.update()["log"]) + _("-core"))
ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(msg))
# New line # New line
ret.append(self.curse_new_line()) ret.append(self.curse_new_line())

View File

@ -25,7 +25,7 @@ except ImportError:
pass pass
# Import Glances lib # Import Glances lib
from glances.core.glances_globals import is_python3 from glances.core.glances_globals import is_py3
from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin
from glances.plugins.glances_plugin import GlancesPlugin from glances.plugins.glances_plugin import GlancesPlugin
@ -124,7 +124,7 @@ class Plugin(GlancesPlugin):
# Header # Header
msg = "{0:18}".format(_("SENSORS")) msg = "{0:18}".format(_("SENSORS"))
ret.append(self.curse_add_line(msg, "TITLE")) ret.append(self.curse_add_line(msg, "TITLE"))
if is_python3: if is_py3:
msg = "{0:>5}".format(_("°C")) msg = "{0:>5}".format(_("°C"))
else: else:
msg = "{0:>6}".format(_("°C")) msg = "{0:>6}".format(_("°C"))

View File

@ -1 +1 @@
psutil>=2.1.0 psutil==2.1.1

View File

@ -1,38 +1,44 @@
#!/usr/bin/env python #!/usr/bin/env python
import glob
import os import os
import sys import sys
import glob
from setuptools import setup from setuptools import setup
data_files = [
('share/doc/glances', ['AUTHORS', 'COPYING', 'NEWS', 'README.rst',
'conf/glances.conf', 'docs/glances-doc.html']),
('share/doc/glances/images', glob.glob('docs/images/*.png')),
('share/man/man1', ['man/glances.1'])
]
if hasattr(sys, 'real_prefix') or 'bsd' in sys.platform: def get_data_files():
conf_path = os.path.join(sys.prefix, 'etc', 'glances') data_files = [
elif not hasattr(sys, 'real_prefix') and 'linux' in sys.platform: ('share/doc/glances', ['AUTHORS', 'COPYING', 'NEWS', 'README.rst',
conf_path = os.path.join('/etc', 'glances') 'conf/glances.conf', 'docs/glances-doc.html']),
elif 'darwin' in sys.platform: ('share/doc/glances/images', glob.glob('docs/images/*.png')),
conf_path = os.path.join('/usr/local', 'etc', 'glances') ('share/man/man1', ['man/glances.1'])
elif 'win32' in sys.platform: ]
conf_path = os.path.join(os.environ.get('APPDATA'), 'glances')
data_files.append((conf_path, ['conf/glances.conf']))
for mo in glob.glob('i18n/*/LC_MESSAGES/*.mo'): if hasattr(sys, 'real_prefix') or 'bsd' in sys.platform:
data_files.append((os.path.dirname(mo).replace('i18n/', 'share/locale/'), [mo])) conf_path = os.path.join(sys.prefix, 'etc', 'glances')
elif not hasattr(sys, 'real_prefix') and 'linux' in sys.platform:
conf_path = os.path.join('/etc', 'glances')
elif 'darwin' in sys.platform:
conf_path = os.path.join('/usr/local', 'etc', 'glances')
elif 'win32' in sys.platform:
conf_path = os.path.join(os.environ.get('APPDATA'), 'glances')
data_files.append((conf_path, ['conf/glances.conf']))
if sys.platform.startswith('win'): for mo in glob.glob('i18n/*/LC_MESSAGES/*.mo'):
requires = ['psutil>=2.0.0', 'colorconsole==0.6'] data_files.append((os.path.dirname(mo).replace('i18n/', 'share/locale/'), [mo]))
else:
return data_files
def get_requires():
requires = ['psutil>=2.0.0'] requires = ['psutil>=2.0.0']
if sys.platform.startswith('win'):
requires += ['colorconsole']
if sys.version_info < (2, 7):
requires += ['argparse']
if sys.version_info < (2, 7): return requires
requires += ['argparse']
setup( setup(
name='Glances', name='Glances',
@ -45,7 +51,7 @@ setup(
# download_url='https://s3.amazonaws.com/glances/glances-2.0.tar.gz', # download_url='https://s3.amazonaws.com/glances/glances-2.0.tar.gz',
license="LGPL", license="LGPL",
keywords="cli curses monitoring system", keywords="cli curses monitoring system",
install_requires=requires, install_requires=get_requires(),
extras_require={ extras_require={
'WEB': ['bottle'], 'WEB': ['bottle'],
'SENSORS': ['py3sensors'], 'SENSORS': ['py3sensors'],
@ -53,7 +59,7 @@ setup(
}, },
packages=['glances'], packages=['glances'],
include_package_data=True, include_package_data=True,
data_files=data_files, data_files=get_data_files(),
test_suite="glances.tests", test_suite="glances.tests",
entry_points={"console_scripts": ["glances=glances.glances:main"]}, entry_points={"console_scripts": ["glances=glances.glances:main"]},
classifiers=[ classifiers=[