aboutsummaryrefslogtreecommitdiff
path: root/sgdfi/_manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'sgdfi/_manager.py')
-rwxr-xr-xsgdfi/_manager.py353
1 files changed, 198 insertions, 155 deletions
diff --git a/sgdfi/_manager.py b/sgdfi/_manager.py
index 8442817..aec2eb4 100755
--- a/sgdfi/_manager.py
+++ b/sgdfi/_manager.py
@@ -82,30 +82,6 @@ class _AjaxField:
return self.__text
-class _OperationManager:
- """ The operations manager. """
-
- def __init__(self, main):
- self.__main = main
-
- def add(self, op):
- if not isinstance(op, _Operation):
- raise ValueError("Expected an 'Operation'.")
-
- self.__main.add_op(op)
-
-class _PlaceManager:
- """ The place manager. """
-
- def __init__(self, main):
- self.__main = main
-
- def add(self, pl):
- if not isinstance(pl, _Place):
- raise ValueError("Expected a 'Place'.")
-
- self.__main.add_place(pl)
-
class _StructureManager:
""" The structure manager. """
@@ -130,6 +106,54 @@ class _AdherentManager:
self.__main.add_adherent(ad)
+class _RallyRegistrationManager:
+ """ The rally registration manager. """
+
+ def __init__(self, main):
+ self.__main = main
+
+ def add(self, rreg):
+ if not isinstance(rreg, _RallyRegistration):
+ raise ValueError("Expected a 'RellyRegistration'.")
+
+ self.__main.add_rally_registration(rreg)
+
+class _CampManager:
+ """ The camp manager. """
+
+ def __init__(self, main):
+ self.__main = main
+
+ def add(self, cp):
+ if not isinstance(cp, _Camp):
+ raise ValueError("Expected a 'Camp'.")
+
+ self.__main.add_camp(cp)
+
+class _PlaceManager:
+ """ The place manager. """
+
+ def __init__(self, main):
+ self.__main = main
+
+ def add(self, pl):
+ if not isinstance(pl, _Place):
+ raise ValueError("Expected a 'Place'.")
+
+ self.__main.add_place(pl)
+
+class _OperationManager:
+ """ The operations manager. """
+
+ def __init__(self, main):
+ self.__main = main
+
+ def add(self, op):
+ if not isinstance(op, _Operation):
+ raise ValueError("Expected an 'Operation'.")
+
+ self.__main.add_op(op)
+
# The main class.
_type = type
@@ -154,23 +178,14 @@ class Manager:
# Make the data manager.
- data = _Database(cache_dir = cache_dir)
- self.__ops = _OperationManager(data)
- self.__pls = _PlaceManager(data)
- self.__sts = _StructureManager(data)
- self.__ads = _AdherentManager(data)
+ self.__db = _Database(cache_dir = cache_dir)
- @property
- def operations(self):
- """ The operations manager. """
-
- return self.__ops
-
- @property
- def places(self):
- """ The places manager. """
-
- return self.__pls
+ self.__sts = _StructureManager(self.__db)
+ self.__ads = _AdherentManager(self.__db)
+ self.__rrs = _RallyRegistrationManager(self.__db)
+ self.__cps = _CampManager(self.__db)
+ self.__pls = _PlaceManager(self.__db)
+ self.__ops = _OperationManager(self.__db)
@property
def structures(self):
@@ -184,6 +199,30 @@ class Manager:
return self.__ads
+ @property
+ def rally_registrations(self):
+ """ The rally registrations manager. """
+
+ return self.__rrs
+
+ @property
+ def camps(self):
+ """ The camps manager. """
+
+ return self.__cps
+
+ @property
+ def places(self):
+ """ The places manager. """
+
+ return self.__pls
+
+ @property
+ def operations(self):
+ """ The operations manager. """
+
+ return self.__ops
+
# ---
# Save file management.
# ---
@@ -403,119 +442,6 @@ class Manager:
# HTML pages and fragments decoding.
# ---
- def __feed_json_functions(self, content):
- """ Decode the JSON functions autocompletion data and return
- them without feeding the database. """
-
- def _sfix(code):
- if code[-1:] == "L" or code[:1] == "3":
- return "_L"
- if code[-1:] == "N" or code[:1] == "6":
- return "_N"
- if code[-1:] == "T" or code[:1] == "9":
- return "_T"
- return ""
-
- def _cname(cname):
- """ Make a canonical name out of a name. """
-
- cfilt = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
-
- cname = cname.casefold().upper()
- cname = cname.replace(' - ', ' ')
- cname = cname.replace(' !', '')
- cname = cname.replace(' ', ' ')
- cname = cname.replace("D'", '')
- cname = cname.replace(' ', '_')
- cname = cname.replace('É', 'E')
- cname = cname.replace('À', 'A')
- cname = ''.join(filter(lambda c: c in cfilt, cname))
-
- return cname
-
- # First phase: load from the JSON and store as an array under the
- # constant name.
-
- funcs = {}
-
- for idx, value in enumerate(content):
- iid = int(value['id'])
- name = value['name']
-
- code, rest = name.split('(')
- code = code.strip()
- rest = rest.split(')')[0]
-
- rest = rest.split('/')
- nm = rest[0].strip()
- if len(rest) == 1:
- nf = None
- else:
- nf = '/'.join(rest[1:])
- nf = nf.strip()
- if nf == nm:
- nf = None
-
- cnames = [_cname(nm)]
- if nf is not None and _cname(nf) != _cname(nm):
- cnames.append(_cname(nf))
-
- func = _FunctionRawData(iid, code, nm, nf, cnames, idx + 1)
-
- for cname in cnames:
- if not cname in funcs:
- funcs[cname] = []
- funcs[cname].append(func)
-
- # Second phase: disambiguation.
-
- while True:
- try:
- cname = next(cn for cn in funcs.keys() if len(funcs[cn]) > 1)
- except StopIteration:
- break
-
- disf = funcs[cname]
- del funcs[cname]
-
- # We ought to find a solution to make other canonical names.
-
- codes = [func.code for func in disf]
- sfix = [_sfix(code) for code in codes]
- if len(sfix) > len(set(sfix)):
- raise ValueError(f"Could not deduplicate using scale: {codes}")
-
- for func, suffix in zip(disf, sfix):
- # Delete all the current function references.
-
- for cname in func.cnames:
- try:
- f = funcs[cname]
- except KeyError:
- continue
-
- f.remove(func)
- if not f:
- del funcs[cname]
-
- # Replace all of the cnames.
-
- func = func.add_cname_suffix(suffix)
-
- # Add all of the references again.
-
- for cname in func.cnames:
- if not cname in funcs:
- funcs[cname] = []
- funcs[cname].append(func)
-
- # Third phase: flatten the functions and we're done!
-
- funcs = list(set(func[0] for func in funcs.values()))
- funcs.sort(key = lambda x: x.srcorder)
-
- return funcs
-
def __feed_html_operations(self, content):
""" Decode the HTML operations from a BeautifulSoup decoded
content and feed it into the manager's operations. """
@@ -1029,8 +955,125 @@ class Manager:
return people
# ---
- # Export functions as a Python file to replace the one
- # in `_dbs/_funcdata.py`.
+ # JSON documents decoding.
+ # ---
+
+ def __feed_json_functions(self, content):
+ """ Decode the JSON functions autocompletion data and return
+ them without feeding the database. """
+
+ def _sfix(code):
+ if code[-1:] == "L" or code[:1] == "3":
+ return "_L"
+ if code[-1:] == "N" or code[:1] == "6":
+ return "_N"
+ if code[-1:] == "T" or code[:1] == "9":
+ return "_T"
+ return ""
+
+ def _cname(cname):
+ """ Make a canonical name out of a name. """
+
+ cfilt = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
+
+ cname = cname.casefold().upper()
+ cname = cname.replace(' - ', ' ')
+ cname = cname.replace(' !', '')
+ cname = cname.replace(' ', ' ')
+ cname = cname.replace("D'", '')
+ cname = cname.replace(' ', '_')
+ cname = cname.replace('É', 'E')
+ cname = cname.replace('À', 'A')
+ cname = ''.join(filter(lambda c: c in cfilt, cname))
+
+ return cname
+
+ # First phase: load from the JSON and store as an array under the
+ # constant name.
+
+ funcs = {}
+
+ for idx, value in enumerate(content):
+ iid = int(value['id'])
+ name = value['name']
+
+ code, rest = name.split('(')
+ code = code.strip()
+ rest = rest.split(')')[0]
+
+ rest = rest.split('/')
+ nm = rest[0].strip()
+ if len(rest) == 1:
+ nf = None
+ else:
+ nf = '/'.join(rest[1:])
+ nf = nf.strip()
+ if nf == nm:
+ nf = None
+
+ cnames = [_cname(nm)]
+ if nf is not None and _cname(nf) != _cname(nm):
+ cnames.append(_cname(nf))
+
+ func = _FunctionRawData(iid, code, nm, nf, cnames, idx + 1)
+
+ for cname in cnames:
+ if not cname in funcs:
+ funcs[cname] = []
+ funcs[cname].append(func)
+
+ # Second phase: disambiguation.
+
+ while True:
+ try:
+ cname = next(cn for cn in funcs.keys() if len(funcs[cn]) > 1)
+ except StopIteration:
+ break
+
+ disf = funcs[cname]
+ del funcs[cname]
+
+ # We ought to find a solution to make other canonical names.
+
+ codes = [func.code for func in disf]
+ sfix = [_sfix(code) for code in codes]
+ if len(sfix) > len(set(sfix)):
+ raise ValueError(f"Could not deduplicate using scale: {codes}")
+
+ for func, suffix in zip(disf, sfix):
+ # Delete all the current function references.
+
+ for cname in func.cnames:
+ try:
+ f = funcs[cname]
+ except KeyError:
+ continue
+
+ f.remove(func)
+ if not f:
+ del funcs[cname]
+
+ # Replace all of the cnames.
+
+ func = func.add_cname_suffix(suffix)
+
+ # Add all of the references again.
+
+ for cname in func.cnames:
+ if not cname in funcs:
+ funcs[cname] = []
+ funcs[cname].append(func)
+
+ # Third phase: flatten the functions and we're done!
+
+ funcs = list(set(func[0] for func in funcs.values()))
+ funcs.sort(key = lambda x: x.srcorder)
+
+ return funcs
+
+ # ---
+ # Export dynamically gathered data such as functions as Python files
+ # to replace some of those in the `_dbs` submodule.
# ---
def export_functions(self, functions, to = _stdout):