Commit 9a34865f authored by Oskar Skog's avatar Oskar Skog

Test 0.2.20: cursescfg B&W fix; configuration file installation "policy" changed

parent bb4e751b
2016-07-18 Oskar Skog <oskar.skog.finland@gmail.com>
0.2.20
* cursescfg: Difficult to see anything in B&W mode: Change '?' to '.'
to increase the visual difference between flags and free cells.
* INSTALL: Updated to match these changes:
* Makefile.static: Disabled overwrite-cfg due to the new behavior
of check-install-cfg.
* install-cfg:
- Wrote docstrings
- Changed return values for `decide`
- Tell which configuration file is incompatible and refer to the
source file.
* install-cfg, Configuration files: Added support for a status quo
marker line. If the magic line can be found in the destination
file, it will be overwritten.
* install-cfg, Makefile.static (check-install-cfg): Send the verbose
variable to ./install-cfg to make it shut up if it has nothing
exceptional to say.
2016-07-17 Oskar Skog <oskar.skog.finland@gmail.com>
0.2.19
* cursescfg: Hexagonal grid was still too bright -> set to A_DIM,
......
......@@ -236,14 +236,10 @@ ADVANCED INSTALLATION
Print where things will be installed.
install
Configuration files will not be replaced by this target.
Installation will fails if the pre-existing configuration files
are incompatible with the new version of the software, and the
old version should be left untouched.
overwrite-cfg
Overwrite the configuration files.
NOTICE: This does not ask for confirmation.
Altered configuration files will not be touched by this target.
If the existing configuration file is incompatible but does not
identify itself as unmodified, installation will fail and the
configuration file must be manually edited.
uninstall
This will remove the system-wide configuration files as well.
......
......@@ -12,7 +12,7 @@
NAME := anonymine
NAME_C := Anonymine
DESCRIPTION = Minesweeper without guessing
VERSION := 0.2.19
VERSION := 0.2.20
# Five more variables are required: sysconfdir, vargamesdir, EXECUTABLES and
# MODULES, and MODULES_OTHERVER which may be set to "non-existent".
......@@ -149,10 +149,12 @@ check-install-cfg : FORCE
@: # Install the directory for the configuration files as install-dirs
@: # might not have been run yet.
@mkdir -p "$(CFG_DIR)"
@$(INSTALL_CFG) "$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg"
@$(INSTALL_CFG) "$(ENGINECFG_STAGE)" "$(CFG_DIR)/enginecfg"
@$(INSTALL_CFG) "$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg" $(verbose)
@$(INSTALL_CFG) "$(ENGINECFG_STAGE)" "$(CFG_DIR)/enginecfg" $(verbose)
overwrite-cfg: FORCE
@echo "overwrite-cfg has been disabled" >/dev/stderr && false
@false
@$(INSTALL) -m 644 "$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg"
@$(INSTALL) -m 644 "$(ENGINECFG_STAGE)" "$(CFG_DIR)/enginecfg"
@$(info) "Configuration has been overwritten"
......
......@@ -62,7 +62,7 @@ except:
GAME_NAME = 'Anonymine'
GAME_FILENAME = GAME_NAME.lower().replace(' ', '-')
GAME_VERSION = (0, 2, 19)
GAME_VERSION = (0, 2, 20)
# GAME_VERSION MAY lag behind the version of the package when no change has
# been made to this file.
GAME_CRAPTEXT = """{0} version {1}.{2}.{3}
......
......@@ -11,7 +11,7 @@ if [ $# -eq 1 ]; then
done
for version_option in -V --version; do
if [ "$1" = $version_option ]; then
echo Anonymine 0.2.19
echo Anonymine 0.2.20
echo Handmade configure and configure.py
echo Version info from ./configure may lag behind.
exit
......
#!/usr/bin/python
#@not-modified@
# Remove the above line if this file has been modified.
# If you don't, this file will be overwritten.
# NOTICE:
# The keys (the format) may change when you update the game. If that
......@@ -138,7 +140,7 @@
# pair foreground attributes
#key character background
'flag': (1, 'F', "BLACK", "YELLOW", curses.A_NORMAL),
'free': (2, '?', "BLACK", "BLACK", curses.A_NORMAL),
'free': (2, '.', "BLACK", "BLACK", curses.A_NORMAL),
'number': (3, None, "GREEN", "BLACK", curses.A_BOLD),
'zero': (3, '-', "GREEN", "BLACK", curses.A_BOLD),
'mine': (4, 'X', "RED", "BLACK", curses.A_BLINK),
......
#!/usr/bin/python
#@not-modified@
# Remove the above line if this file has been modified.
# If you don't, this file will be overwritten.
{
'init-field': {
'procs': 1, # Default is to not overload.
......
#!/usr/bin/python
# INTENDED TO BE EXECUTED WITH `python install-cfg src dest`
# INTENDED TO BE EXECUTED WITH `python install-cfg src dest verbose`
import os
import sys
......@@ -7,6 +7,7 @@ import sys
import curses # Used by the std cfg.
def scan_cfg(src_cfg, dest_cfg):
'''Does `src_cfg` have something new that `dest_cfg` doesn't?'''
for key in src_cfg:
if key not in dest_cfg:
return True
......@@ -24,7 +25,16 @@ def scan_cfg(src_cfg, dest_cfg):
return True
return False
def decide(src, dest):
def decide(src, dest, verbose=True):
'''
Decide what needs to be done to install the configuration file
from `src` to `dest`.
Returns
'install' if the `dest` should be overwritten with `src`.
'fail' if it can't be installed automatically.
'skip' if it should not be installed/overwritten.
'''
try:
src_cfg = eval(open(src).read())
except:
......@@ -33,26 +43,41 @@ def decide(src, dest):
"Cannot load the source configuration files.\n"
"\n"
)
return False, False
# Only install the file if it hasn't already been installed.
return 'fail'
# Install the file if it hasn't already been installed.
try:
dest_file = open(dest)
except IOError:
return True, True
return 'install'
try:
dest_cfg = eval(dest_file.read())
content = dest_file.read()
except:
sys.stderr.write(
"\nERROR:\n"
"Cannot open the pre-existing configuration file.\n"
"\n"
)
# Install if file has not been modified.
magic = '#@not-modified@\n'
if '\n'+magic in content or content.startswith(magic):
if verbose:
sys.stderr.write(
"\nINFORMATIONAL:\n"
"The already existing configuration file is at its default\n"
"and will therefore be overwritten to install any changes.\n"
)
return 'install'
# Check if the pre-existing configuration is usable.
try:
dest_cfg = eval(content)
except:
sys.stderr.write(
"\nERROR:\n"
"Cannot parse the pre-existing configuration.\n"
"\n"
)
return False, False
return 'fail'
dest_file.close()
if scan_cfg(src_cfg, dest_cfg):
sys.stderr.write(
"\nNOTICE:\n"
......@@ -60,27 +85,50 @@ def decide(src, dest):
"version. Manual installation of the installation file required.\n"
"\n"
)
return False, False
return 'fail'
else:
sys.stderr.write(
"\nINFORMATIONAL:\n"
"The configuration is already installed and should be usable\n"
"by the newly installed version of the program.\n"
"\n"
)
return False, True
if verbose:
sys.stderr.write(
"\nINFORMATIONAL:\n"
"The configuration is already installed and should be usable\n"
"by the newly installed version of the program.\n"
"\n"
)
return 'skip'
def main():
if len(sys.argv) != 4:
sys.stderr.write("Usage: python install-cfg install-cmd src dest\n")
if len(sys.argv) != 5:
sys.stderr.write(
"Usage: python install-cfg install-cmd src dest verbose\n"
)
sys.exit(1)
install_cmd, src, dest = sys.argv[1], sys.argv[2], sys.argv[3]
install, success = decide(src, dest)
if not success:
if sys.argv[4] == 'true':
verbose = True
elif sys.argv[4] == 'false':
verbose = False
else:
verbose = True
sys.stderr.write(
'The <verbose> parameter must be "true" or "false".\n'
)
status = decide(src, dest, verbose)
if status == 'fail':
sys.stderr.write("Error: Cannot install automatically.\n")
sys.stderr.write(
'"{0}" is incompatible and must be edited\n'.format(dest)
)
sys.stderr.write(
'Look at "{0}" to know what changes must be made.\n'.format(src)
)
sys.exit(1)
if install:
elif status == 'install':
os.system('{0} -m 644 "{1}" "{2}"'.format(install_cmd, src, dest))
elif status == 'skip':
pass
else:
sys.stderr.write('Internal error!\n')
if __name__ == '__main__':
main()
......@@ -38,7 +38,11 @@ def main():
procs = int(0.83 * cpus + 0.5)
hiscorefile = sys.argv[2]
sys.stdout.write('''# Auto generated during "build".
sys.stdout.write('''#!/usr/bin/python
#@not-modified@
# Remove the above line if this file has been modified.
# If you don't, this file will be overwritten.
# Auto generated during "build".
{
'init-field': {
'procs': '''+str(procs)+''',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment