Commit c5259086 authored by Oskar Skog's avatar Oskar Skog

0.2.8: Install highscores file

parent e0e7ee7e
2016-07-14 Oskar Skog <[email protected]>
0.2.8
* configure.py: New functions: find_sysconfdir and find_vargamesdir.
* anonymine.py, configure.py, Makefile.static: Place configuration
files in $(sysconfdir)/anonymine
* Makefile.static: enginecfg calibration message updated.
* mkenginecfg, Makefile.static: Install highscore file.
* mkenginecfg: time and pprint modules are no longer needed.
* mkenginecfg: Write out the configuration file manually.
0.2.7
* anonymine_engine.py anonymine.py: Python 3 fixes:
- anonymine_engine.hiscores.display.format_deltatime formatted
......
......@@ -12,7 +12,7 @@
NAME := anonymine
NAME_C := Anonymine
DESCRIPTION = Minesweeper without guessing
VERSION := 0.2.7
VERSION := 0.2.8
# Three more variables are required: EXECUTABLES and MODULES
# and MODULES_OTHERVER (= "non-existent").
......@@ -50,6 +50,7 @@ MAIN_SRC := $(srcdir)$(NAME).py
MAIN_STAGE := $(builddir)$(NAME)
MAIN_DEST := $(DESTDIR)$(EXECUTABLES)/$(NAME)
HISCORE_FILE := $(vargamesdir)/anonymine
ENGINECFG_STAGE := $(builddir)enginecfg.out
# freedesktop.org, see desktop/README
......@@ -89,8 +90,8 @@ $(MAIN_STAGE) : $(MAIN_SRC)
@cat "$(MAIN_SRC)" >> "$(MAIN_STAGE)"
$(ENGINECFG_STAGE) : $(srcdir)mkenginecfg
@$(info) 'Calibrating enginecfg: 10^8 no-ops'
@"$(srcdir)mkenginecfg" "$(srcdir)" "$(builddir)"
@$(info) 'Making enginecfg: mostly counting processors'
@"$(srcdir)mkenginecfg" "$(srcdir)" "$(builddir)" "$(HISCORE_FILE)"
build-freedesktop : FORCE
@: # Refer to desktop/README for information about the following.
......@@ -116,7 +117,7 @@ INSTALL ?= install
INSTALL_CFG := python "$(srcdir)install-cfg" "$(INSTALL)"
CFG_DIR := $(DESTDIR)/etc/$(NAME)
CFG_DIR := $(DESTDIR)$(sysconfdir)/$(NAME)
# Modules: FOO_SRC, FOO_DEST, FOO_DEST_OTHERVER
ENGINE_SRC := $(srcdir)$(NAME)_engine.py
ENGINE_DEST := $(DESTDIR)$(MODULES)/$(NAME)_engine.py
......@@ -181,6 +182,9 @@ install : check-install-cfg install-dirs
@$(INSTALL) -m 644 "$(ENGINE_SRC)" "$(ENGINE_DEST)"
@$(INSTALL) -m 644 "$(SOLVER_SRC)" "$(SOLVER_DEST)"
@$(INSTALL) -m 644 "$(FIELDS_SRC)" "$(FIELDS_DEST)"
@: # Create highscore file unless it already exists.
@touch "$(HISCORE_FILE)"
@chmod 666 "$(HISCORE_FILE)"
@if [ -n "$(freedesktop)" ]; then \
$(info) 'Installing icons and .desktop (NORMAL_INSTALL)'; \
$(INSTALL) -m 644 "$(FD_DESKTOP_STAGE)" "$(FD_DESKTOP_DEST)"; \
......
......@@ -63,7 +63,7 @@ except:
GAME_NAME = 'Anonymine'
GAME_FILENAME = GAME_NAME.lower().replace(' ', '-')
GAME_VERSION = (0, 2, 7)
GAME_VERSION = (0, 2, 8)
# 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}
......@@ -1361,6 +1361,7 @@ def main():
else:
locations = (
os.path.expanduser('~/.' + GAME_FILENAME + '/' + cfgfile),
sys.prefix + '/etc/' + GAME_FILENAME + '/' + cfgfile,
'/etc/' + GAME_FILENAME + '/' + cfgfile,
)
for location in locations:
......
......@@ -11,9 +11,9 @@ if [ $# -eq 1 ]; then
done
for version_option in -V --version; do
if [ "$1" = $version_option ]; then
echo Anonymine 0.2.7
echo Anonymine 0.2.8
echo Handmade configure and configure.py
echo Version info from configure may lag behind.
echo Version info from ./configure may lag behind.
exit
fi
done
......
......@@ -240,10 +240,55 @@ def find_EXECUTABLES(Makefile, flags):
else:
return False
def find_sysconfdir(Makefile, flags):
'''
'''
if 'sysconfdir' in Makefile:
if expand('sysconfdir', Makefile) not in ('/etc', sys.prefix+'/etc'):
sys.stderr.write('Will not be able to find configuration\n')
return True
else:
return False
else:
if Makefile['prefix'] == sys.prefix:
try:
os.listdir(Makefile['prefix'] + '/etc')
Makefile['sysconfdir'] = '$(prefix)/etc'
return False
except:
pass
Makefile['sysconfdir'] = '/etc'
return False
def find_vargamesdir(Makefile, flags):
'''
'''
if 'localstatedir' not in Makefile:
try:
os.listdir(Makefile['prefix'] + '/var')
Makefile['localstatedir'] = '$(prefix)/var'
except:
try:
os.listdir('/var')
Makefile['localstatedir'] = '/var'
except:
return True
if 'vargamesdir' not in Makefile:
for tail in ('/games', ''):
try:
os.listdir(Makefile['localstatedir'] + tail)
Makefile['vargamesdir'] = '$(localstatedir)' + tail
return False
except:
pass
else:
return True
else:
return False
def get_module_dir(libdir, acceptable, major, minor):
'''
'''
major, minor = str(major), str(minor)
single = str(major)
dual = str(major) + '.' + str(minor)
......@@ -387,6 +432,8 @@ def main():
error |= find_EXECUTABLES(Makefile, flags)
error |= find_MODULES(Makefile, flags)
ignore = find_MODULES_OTHERVER(Makefile, flags)
error |= find_sysconfdir(Makefile, flags)
error |= find_vargamesdir(Makefile, flags)
# and the install tool.
error |= find_INSTALL_CMD(Makefile, flags)
#
......@@ -407,6 +454,8 @@ def main():
'freedesktop',
'macosx',
'windows',
'sysconfdir',
'vargamesdir',
)
for variable in of_interest:
try:
......
#!/bin/sh
# ./mkenginecfg srcdir builddir
# ./mkenginecfg srcdir builddir hiscorefile
# TODO: measure time by the time it takes to solve some known fields.
......@@ -9,6 +9,7 @@
srcdir=$1
builddir=$2
hiscorefile=$3
userfile="${builddir}enginecfg.user"
defaultfile="${srcdir}enginecfg.default"
......@@ -23,8 +24,6 @@ if [ -f "$userfile" ]; then
fi
cat > "$pyfile" << __EOF__
import pprint
import time
import sys
def main():
......@@ -38,20 +37,24 @@ def main():
cpus = 1
procs = int(0.83 * cpus + 0.5)
cfg = {
'init-field': {
'procs': procs,
'filename': '/tmp/mines.{0}',
'sec-maxtime': 90,
'sec-maxarea': 10000,
}
}
sys.stdout.write('# Auto generated during "build".\n')
sys.stdout.write(pprint.pformat(cfg))
sys.stdout.write('\n')
sys.stdout.close()
hiscorefile = sys.argv[2]
sys.stdout.write('''# Auto generated during "build".
{
'init-field': {
'procs': '''+str(procs)+''',
'filename': '/tmp/mines.{0}',
'sec-maxtime': 90, # Security timeout
'sec-maxarea': 10000, # Maximum allowed area
},
'hiscores': {
'file': "'''+str(hiscorefile)+'''",
'entries': 10, # Top N, how many entries per sublist
'maxsize': 524288, # Security: Maximum allowed filesize
'use-user': True, # List login names
'use-nick': True, # Let players choose their own names
},
}
''')
if __name__ == '__main__':
main()
......@@ -74,5 +77,5 @@ done
oldpwd=`pwd`
cd "$srcdir"
python "$pyfile" $ncpus > "$outfile" || cp "$defaultfile" "$outfile"
python "$pyfile" $ncpus "$hiscorefile" > "$outfile" || cp "$defaultfile" "$outfile"
cd "$oldpwd"
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