Browse Source

New dependency: appdirs. This may help crossplatform portability.

master
Doug Le Tough 4 years ago
parent
commit
7c0b0d5962
5 changed files with 64 additions and 31 deletions
  1. +7
    -5
      README.md
  2. +3
    -6
      logger/__init__.py
  3. +12
    -12
      pycursesvirtmgr.py
  4. +37
    -0
      ui/KEY_REFERENCE.TXT
  5. +5
    -8
      ui/__init__.py

+ 7
- 5
README.md View File

@ -23,7 +23,7 @@ This project aims to be a convenient UI for libvirt usable from a terminal and t
a - An Unix-like system (Linux/BSD/MacOSX/...)
Due to some limitations of the underlying operating system,
Windows is not not supported by this program.
b - A terminal or a terminal emulator such xterm able to display
colors and supports least a 40 lines X 150 columns resolution.
This software will work nicely with terminal multiplexers like
@ -31,7 +31,9 @@ This project aims to be a convenient UI for libvirt usable from a terminal and t
c - Python 2.7.x
This Program will simply *NOT* run with Python3 but may be converted if necessary.
d - The python-libvirt modules
e - The python-curses modules
d - The python-curses module (should be part of standard python installation)
e - The python-libvirt module (pip install libvirt)
f - The python-appdirs module (pip install appdirs)

+ 3
- 6
logger/__init__.py View File

@ -4,17 +4,14 @@
import os
class Logger(object):
def __init__(self, log_path=None, debug=True, level='error'):
def __init__(self, log_dir, debug=True, level='error'):
self.debug = debug
self.levels = {'error': 0, 'warning': 1, 'info': 2}
self.level = level
if not log_path:
log_path = '/tmp'
self.create_log(log_path)
self.create_log(log_dir)
def create_log(self, log_path):
def create_log(self, log_dir):
""" Create log dir and delete existing log """
log_dir = os.path.join(log_path, 'pyCursesVirtMgr', 'log')
self.log_file = os.path.join(log_dir, 'pyCursesVirtMgr.log')
if not os.path.exists(log_dir):
os.makedirs(log_dir)


+ 12
- 12
pycursesvirtmgr.py View File

@ -3,27 +3,26 @@
import os, shutil
import curses
from appdirs import *
import data_manager
from ui import UI, display_manager
from logger import Logger
def check_install():
script_name = os.path.basename(os.path.realpath(__file__))
def check_install(dirs):
script_path = os.path.dirname(os.path.realpath(__file__))
original_conf_path = os.path.join(script_path, 'config')
user_home = os.environ['HOME']
user_config_dir = os.path.join(user_home, '.config', script_name)
if not os.path.exists(user_config_dir):
config_dir = dirs.user_config_dir
if not os.path.exists(config_dir):
try:
print '\033[92mCreating config directory:\033[0m %s' % user_config_dir
os.makedirs(user_config_dir)
print '\033[92mCreating config directory:\033[0m %s' % config_dir
os.makedirs(config_dir)
except Exception as e:
print '\033[91mError while trying to create %s:\n%s\033[0m' % (user_config_dir, str(e))
print '\033[91mError while trying to create %s:\n%s\033[0m' % (config_dir, str(e))
exit(1)
print '\033[92mCopying configuration file from package to confidir :\033[0m'
print '\033[92mCopying configuration file from package to config dir %s/ :\033[0m' % config_dir
for conf_file in os.listdir(original_conf_path):
original_conf_file = os.path.join(original_conf_path, conf_file)
dest_file = os.path.join(user_config_dir, conf_file)
dest_file = os.path.join(config_dir, conf_file)
if os.path.isfile(original_conf_file):
print '* %s -> %s' % (original_conf_file, dest_file)
shutil.copy(original_conf_file, dest_file)
@ -34,8 +33,9 @@ if __name__ == "__main__":
#~ displayManager = display_manager.DisplayManager(dataManager, logger)
#~ ui = UI(15, 150, displayManager, logger)
try:
check_install()
logger = Logger('/tmp/', True, 'info')
dirs = AppDirs("pyCursesVirtMgr", "Red AtomiK")
check_install(dirs)
logger = Logger(dirs.user_log_dir, True, 'info')
dataManager = data_manager.DataManager(logger)
displayManager = display_manager.DisplayManager(dataManager, logger)
ui = UI(15, 150, displayManager, logger)


+ 37
- 0
ui/KEY_REFERENCE.TXT View File

@ -22,3 +22,40 @@ curses.ascii.BS,
curses.ascii.TAB,
curses.ascii.LF,
curses.ascii.ESC,
NUL
SOH Start of heading, console interrupt
STX Start of text
ETX End of text
EOT End of transmission
ENQ Enquiry, goes with ACK flow control
ACK Acknowledgement
BEL Bell
BS Backspace
TAB Tab
HT Alias for TAB: “Horizontal tab”
LF Line feed
NL Alias for LF: “New line”
VT Vertical tab
FF Form feed
CR Carriage return
SO Shift-out, begin alternate character set
SI Shift-in, resume default character set
DLE Data-link escape
DC1 XON, for flow control
DC2 Device control 2, block-mode flow control
DC3 XOFF, for flow control
DC4 Device control 4
NAK Negative acknowledgement
SYN Synchronous idle
ETB End transmission block
CAN Cancel
EM End of medium
SUB Substitute
ESC Escape
FS File separator
GS Group separator
RS Record separator, block-mode terminator
US Unit separator
SP Space
DEL Delete

+ 5
- 8
ui/__init__.py View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
from appdirs import *
import locale
import curses
from ui import window, input_manager, display_manager
@ -13,14 +14,10 @@ locale.setlocale(locale.LC_ALL, '')
class UI(object):
""" The main U.I class"""
def __init__(self, min_lines, min_cols, displayManager, logger):
self.windows_conf_file = os.path.join(os.environ['HOME'],
'.config',
'pycursesvirtmgr.py',
'windows_definition.py')
self.menu_conf_file = os.path.join(os.environ['HOME'],
'.config',
'pycursesvirtmgr.py',
'main_menu.py')
dirs = AppDirs("pyCursesVirtMgr", "Red AtomiK")
config_dir = dirs.user_config_dir
self.windows_conf_file = os.path.join(config_dir, 'windows_definition.py')
self.menu_conf_file = os.path.join(config_dir, 'main_menu.py')
self.logger = logger
self.logger.log('Starting U.I', 'info')
self.displayManager = displayManager


Loading…
Cancel
Save