Removed the file_server sub-directory.

master
Pacman Ghost 5 years ago
parent 08728b20c8
commit 31d2dcece1
  1. 2
      vasl_templates/server_settings.py
  2. 6
      vasl_templates/webapp/file_server/__init__.py
  3. 65
      vasl_templates/webapp/file_server/utils.py
  4. 2
      vasl_templates/webapp/files.py
  5. 11
      vasl_templates/webapp/tests/remote.py
  6. 3
      vasl_templates/webapp/tests/test_counters.py
  7. 62
      vasl_templates/webapp/vasl_mod.py
  8. 2
      vasl_templates/webapp/vassal.py
  9. 2
      vasl_templates/webapp/vo.py
  10. 2
      vasl_templates/webapp/vo_notes.py

@ -12,8 +12,8 @@ from vasl_templates.main import app_settings
from vasl_templates.main_window import MainWindow
from vasl_templates.utils import show_msg_store
from vasl_templates.webapp.vassal import VassalShim, SUPPORTED_VASSAL_VERSIONS_DISPLAY
from vasl_templates.webapp.vasl_mod import set_vasl_mod, SUPPORTED_VASL_MOD_VERSIONS_DISPLAY
from vasl_templates.webapp.utils import MsgStore
from vasl_templates.webapp.file_server.vasl_mod import set_vasl_mod, SUPPORTED_VASL_MOD_VERSIONS_DISPLAY
# ---------------------------------------------------------------------

@ -1,6 +0,0 @@
""" Classes to serve files from various sources.
This stuff has been split out into a separate package so that it can be imported into the asl-rulebook project,
since that will often be running while a game is being played, so that can provide these services, without having
to run this project as well.
"""

@ -1,65 +0,0 @@
""" Miscellaneous utilities. """
import os
import json
# ---------------------------------------------------------------------
def get_vo_gpids( data_dir, extns ): #pylint: disable=too-many-locals,too-many-branches
"""Get the GPID's for the vehicles/ordnance."""
gpids = set()
for vo_type in ("vehicles","ordnance"): #pylint: disable=too-many-nested-blocks
# process each file
dname = os.path.join( data_dir, vo_type )
for root,_,fnames in os.walk(dname):
for fname in fnames:
if os.path.splitext(fname)[1] != ".json":
continue
# load the GPID's from the next file
# NOTE: We originally assumed that GPID's are integers, but the main VASL build file started
# to have non-numeric values, as do, apparently, extensions :-/ For back-compat, we support both.
entries = json.load( open( os.path.join(root,fname), "r" ) )
for entry in entries:
entry_gpids = entry[ "gpid" ]
if not isinstance( entry_gpids, list ):
entry_gpids = [ entry_gpids ]
for gpid in entry_gpids:
if gpid:
gpids.add( get_effective_gpid( str(gpid) ) )
# process any extensions
if extns: #pylint: disable=too-many-nested-blocks
for extn in extns:
extn_info = extn[1]
for nat in extn_info:
if not isinstance( extn_info[nat], dict ):
continue
for vo_type in ("vehicles","ordnance"):
for piece in extn_info[ nat ].get( vo_type, [] ):
if isinstance( piece["gpid"], list ):
gpids.update( piece["gpid"] )
else:
gpids.add( piece["gpid"] )
return gpids
# ---------------------------------------------------------------------
# VASL 6.4.3 removed several PieceSlot's. There's no comment for the commmit (0a27c24)
# but I suspect it's because they're duplicates. Our data files have the following mappings:
# SdKfz 10/5: 7140, 2775
# SdKfz 10/4: 7146, 2772
# but we can't just remove the now-missing GPID's, since any scenarios that use them
# will break. This kind of thing is going to happen again, so we provide a generic mechanism
# for dealing with this kind of thing...
GPID_REMAPPINGS = {
"7140": "2775", # SdKfz 10/5
"7146": "2772", # SdKfz 10/4
}
def get_effective_gpid( gpid ):
"""Return the effective GPID."""
return GPID_REMAPPINGS.get( gpid, gpid )

@ -9,7 +9,7 @@ import mimetypes
from flask import send_file, send_from_directory, jsonify, redirect, url_for, abort
from vasl_templates.webapp import app
from vasl_templates.webapp.file_server.vasl_mod import get_vasl_mod
from vasl_templates.webapp.vasl_mod import get_vasl_mod
from vasl_templates.webapp.utils import resize_image_response, is_empty_file
# ---------------------------------------------------------------------

@ -22,9 +22,8 @@ from vasl_templates.webapp.config.constants import DATA_DIR
from vasl_templates.webapp import main as webapp_main
from vasl_templates.webapp import snippets as webapp_snippets
from vasl_templates.webapp import vo_notes as webapp_vo_notes
from vasl_templates.webapp.file_server import utils as webapp_file_server_utils
from vasl_templates.webapp.file_server.vasl_mod import set_vasl_mod
from vasl_templates.webapp.file_server import vasl_mod as vasl_mod_module
from vasl_templates.webapp.vasl_mod import set_vasl_mod
from vasl_templates.webapp import vasl_mod as vasl_mod_module
_logger = logging.getLogger( "control_tests" )
@ -116,8 +115,8 @@ class ControlTests:
gpids = json.loads( gpids.replace( "'", '"' ) )
gpids = { str(k): v for k,v in gpids.items() }
_logger.info( "Setting GPID remappings: %s", gpids )
prev_gpid_mappings = webapp_file_server_utils.GPID_REMAPPINGS
webapp_file_server_utils.GPID_REMAPPINGS = gpids
prev_gpid_mappings = vasl_mod_module.GPID_REMAPPINGS
vasl_mod_module.GPID_REMAPPINGS = gpids
return prev_gpid_mappings
def _get_vasl_mods( self ):
@ -181,7 +180,7 @@ class ControlTests:
def _get_vasl_extns( self ): #pylint: disable=no-self-use
"""Return the loaded VASL extensions."""
from vasl_templates.webapp.file_server.vasl_mod import get_vasl_mod
from vasl_templates.webapp.vasl_mod import get_vasl_mod
extns = get_vasl_mod().get_extns()
_logger.debug( "Returning VASL extensions:\n%s",
"\n".join( "- {}".format( e ) for e in extns )

@ -9,8 +9,7 @@ import urllib.request
import pytest
import tabulate
from vasl_templates.webapp.file_server.vasl_mod import VaslMod
from vasl_templates.webapp.file_server.utils import get_vo_gpids
from vasl_templates.webapp.vasl_mod import VaslMod, get_vo_gpids
from vasl_templates.webapp.config.constants import DATA_DIR
from vasl_templates.webapp.tests.utils import init_webapp, select_tab, find_child, find_children
from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario

@ -13,7 +13,6 @@ _logger = logging.getLogger( "vasl_mod" )
from vasl_templates.webapp import app
from vasl_templates.webapp.config.constants import DATA_DIR
from vasl_templates.webapp.file_server.utils import get_vo_gpids, get_effective_gpid
SUPPORTED_VASL_MOD_VERSIONS = [ "6.4.0", "6.4.1", "6.4.2", "6.4.3" ]
SUPPORTED_VASL_MOD_VERSIONS_DISPLAY = "6.4.0-6.4.3"
@ -406,3 +405,64 @@ class VaslMod:
return None
return val[0] if len(val) == 1 else val
return delistify(front_images), delistify(back_images)
# ---------------------------------------------------------------------
def get_vo_gpids( data_dir, extns ): #pylint: disable=too-many-locals,too-many-branches
"""Get the GPID's for the vehicles/ordnance."""
gpids = set()
for vo_type in ("vehicles","ordnance"): #pylint: disable=too-many-nested-blocks
# process each file
dname = os.path.join( data_dir, vo_type )
for root,_,fnames in os.walk(dname):
for fname in fnames:
if os.path.splitext(fname)[1] != ".json":
continue
# load the GPID's from the next file
# NOTE: We originally assumed that GPID's are integers, but the main VASL build file started
# to have non-numeric values, as do, apparently, extensions :-/ For back-compat, we support both.
entries = json.load( open( os.path.join(root,fname), "r" ) )
for entry in entries:
entry_gpids = entry[ "gpid" ]
if not isinstance( entry_gpids, list ):
entry_gpids = [ entry_gpids ]
for gpid in entry_gpids:
if gpid:
gpids.add( get_effective_gpid( str(gpid) ) )
# process any extensions
if extns: #pylint: disable=too-many-nested-blocks
for extn in extns:
extn_info = extn[1]
for nat in extn_info:
if not isinstance( extn_info[nat], dict ):
continue
for vo_type in ("vehicles","ordnance"):
for piece in extn_info[ nat ].get( vo_type, [] ):
if isinstance( piece["gpid"], list ):
gpids.update( piece["gpid"] )
else:
gpids.add( piece["gpid"] )
return gpids
# ---------------------------------------------------------------------
# VASL 6.4.3 removed several PieceSlot's. There's no comment for the commmit (0a27c24)
# but I suspect it's because they're duplicates. Our data files have the following mappings:
# SdKfz 10/5: 7140, 2775
# SdKfz 10/4: 7146, 2772
# but we can't just remove the now-missing GPID's, since any scenarios that use them
# will break. This kind of thing is going to happen again, so we provide a generic mechanism
# for dealing with this kind of thing...
GPID_REMAPPINGS = {
"7140": "2775", # SdKfz 10/5
"7146": "2772", # SdKfz 10/4
}
def get_effective_gpid( gpid ):
"""Return the effective GPID."""
return GPID_REMAPPINGS.get( gpid, gpid )

@ -16,7 +16,7 @@ from flask import request
from vasl_templates.webapp import app
from vasl_templates.webapp.config.constants import BASE_DIR, IS_FROZEN
from vasl_templates.webapp.file_server.vasl_mod import get_vasl_mod
from vasl_templates.webapp.vasl_mod import get_vasl_mod
from vasl_templates.webapp.utils import TempFile, SimpleError
from vasl_templates.webapp.webdriver import WebDriver

@ -8,7 +8,7 @@ from flask import request, render_template, jsonify, abort
from vasl_templates.webapp import app
from vasl_templates.webapp.config.constants import DATA_DIR
from vasl_templates.webapp.file_server.vasl_mod import get_vasl_mod
from vasl_templates.webapp.vasl_mod import get_vasl_mod
# ---------------------------------------------------------------------

@ -9,7 +9,7 @@ from collections import defaultdict
from flask import render_template, jsonify, abort
from vasl_templates.webapp import app
from vasl_templates.webapp.file_server.vasl_mod import get_vasl_mod
from vasl_templates.webapp.vasl_mod import get_vasl_mod
from vasl_templates.webapp.files import FileServer
from vasl_templates.webapp.utils import resize_image_response, is_image_file, is_empty_file

Loading…
Cancel
Save