fixes #2
This commit is contained in:
parent
72004923af
commit
b29823c322
1 changed files with 21 additions and 17 deletions
38
core/app.py
38
core/app.py
|
@ -1,8 +1,10 @@
|
||||||
#! /bin/env python3
|
#! /bin/env python3
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
import xdg.BaseDirectory
|
||||||
|
|
||||||
from . import file
|
from . import file
|
||||||
from . import text
|
from . import text
|
||||||
|
@ -213,31 +215,36 @@ class Main:
|
||||||
* Help system that generates help text based on program's configurable options.
|
* Help system that generates help text based on program's configurable options.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, name, version=None, license=None, cfg_file=None, cmdline=sys.argv[1:], allow_exit=True):
|
def __init__(self, name, full_name, version=None, license=None, use_cfg_file=False, cmdline=sys.argv[1:]):
|
||||||
'''
|
'''
|
||||||
str name program name
|
str name program name (e.g. 'grid')
|
||||||
str version program version
|
str full_name human readable program name (e.g. 'Overwatch Grid')
|
||||||
str license program license
|
str version program version
|
||||||
str cfg_file path to config file, optional
|
str license program license name
|
||||||
list cmdline command line to parse; defaults to system cmdline (sys.argv)
|
str use_cfg_file if True, a config file at ~/.config/(self.name)/main.cfg will be used
|
||||||
|
list cmdline command line to parse; defaults to system cmdline (sys.argv)
|
||||||
|
|
||||||
Initializes over.Main and opens/creates the config file (if desired).
|
Initializes over.Main and opens/creates the config file (if desired).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
self.cfg = CfgAccessor(self)
|
self.cfg = CfgAccessor(self)
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.full_name = full_name
|
||||||
self.version = version
|
self.version = version
|
||||||
self.license = license
|
self.license = license
|
||||||
self.cmdline = cmdline
|
self.cmdline = cmdline
|
||||||
self.help_texts = [] # (chapter, [paragraphs])
|
self.help_texts = [] # (chapter, [paragraphs])
|
||||||
self.allow_exit = allow_exit
|
|
||||||
self._print = text.Output('over.core.app.Main')
|
self._print = text.Output('over.core.app.Main')
|
||||||
|
|
||||||
if cfg_file:
|
self.data_dir = os.path.join(xdg.BaseDirectory.xdg_data_home, self.name)
|
||||||
self.cfg_file = file.File(cfg_file, encoding='utf-8')
|
file.File(os.path.join(self.data_dir, '.keep'))
|
||||||
|
|
||||||
|
if use_cfg_file:
|
||||||
|
self.cfg_file = file.File(os.path.join(xdg.BaseDirectory.xdg_config_home, self.name, 'main.cfg'), encoding='utf-8')
|
||||||
|
|
||||||
if not self.cfg_file.data:
|
if not self.cfg_file.data:
|
||||||
self.cfg_file.data = '''# Et configuration file for %s
|
self.cfg_file.data = '''# Configuration file for %s
|
||||||
# Licensed under the %s
|
# Licensed under the %s
|
||||||
#
|
#
|
||||||
# Syntax
|
# Syntax
|
||||||
|
@ -274,15 +281,12 @@ class Main:
|
||||||
bool silent don't mention it
|
bool silent don't mention it
|
||||||
|
|
||||||
Shutdown the program and exit.
|
Shutdown the program and exit.
|
||||||
|
|
||||||
Can be disabled by setting self.allow_exit to False.
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if self.allow_exit:
|
if not silent:
|
||||||
if not silent:
|
self._print('exiting with §B%d§/' %(retval), prefix.info)
|
||||||
self._print('exiting with §B%d§/' %(retval), prefix.info)
|
|
||||||
|
sys.exit(retval)
|
||||||
sys.exit(retval)
|
|
||||||
|
|
||||||
def dump(self, ignore=[]):
|
def dump(self, ignore=[]):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue