Package: mapactionpy-controller
AboutMaster branchInstallingTo install the latest stable release via PyPi:python -m pip install mapactionpy_controllerTo install a specific version for testing see the relevant commandline from here:https://pypi.org/project/mapactionpy-controller/#historyCommand-line UsageCheck the compliance with the Data Naming Convention, MXD Naming Convention, MXD Template Naming Convention and Layer Naming Convention.> python.exe -m mapactionpy_controller.check_naming_convention /path/to/current/cmf/2019gbr01/cmf_description.jsonUsing the Data Search tool from the command-line> python.exe -m mapactionpy_controller.data_search
usage: data_search [-h] -r FILE -c FILE [-o FILE]
data_search.py: error: the following arguments are required: -r/--recipe-file, -c/--cmf

> python -m mapactionpy_controller.data_search -r example/product_bundle_example.json -c example/cmf_description.jsonThis command will output an updated recipe file with the
If the ouput file parameter (-o) is specified than the updated recipe will be output to that file. Otherwise the updated recipe is sent to stdout.Programmatic UsageUsing the MapRecipe, CrashMoveFolder and Event classesThere are three classes which are designed for reuse in other modules. For each of these there is a corresponding json representation. There should not be any need for any other code to touch these json files:MapRecipe: An object that represents a recipe (as read from a json file).This object may be manipulated by
(e.g. the data_search tool, updates the datasources fields )CrashMoveFolder: An object that describes the CrashMoveFolder and its contents. There should be no need to hardcode any path (absolute or relative) to anywhere in a crash move folderEvent: This describes the real-world humanitarian event to which the Crash Move Folder corresponds.(Note1:) The nameEventmatches the naming of the equivalent concept on the Map & Data Respository (seehttps://github.com/mapaction/ckanext-mapactionevent). However it is rather too generic in this context. A more descriptive name for this class would be helpful.(Note2: in the MapExportTool the information within the CrashMoveFolder and Event used to be encapsulated in theoperational_config.xmlfile. This mixedstateabout the event/emergency andconfigurationabout the local paths to and within the crash move folder.  )Using the DataNameConvention and related classesThenaming_conventionsub-module provides a framework for specifying a naming convention (such as for file or table). A naming convention is specified in a json configuration file and consists of:A regular expression, with named groupsFor each named group in the regex, details of a class which can provide futher validation of that value in that named group.Examples of the naming convention config files are in theexamplesdirectory, including MapAction's DataNamingConvention, MXDNamingConvention and LayerfileNamingConvention.DataNameConventionrepresents theconventionitself. At its core is a regular expression. Each named group (clause) within the Regex as additionally validation, which is implemented by a DataNameClause. DataNameConvention has a dictionary of DataNameClause objects. A individual name is tested by using the.validate(data_name_str)method. If the data name does not match the regex the value None is returned. If the regex matches a DataNameInstance object will be returned, whether or not all of the clauses pass.DataNameClauseis an abstract class. Callers are unlikely to need to directly access this class or any concrete examples. Concrete examples are DataNameFreeTextClause and DataNameLookupClause. When the.validate(data_name_str)method is called on a DataNameConvention object, it will call.validate(clause_str)in each individual DataNameClause obj.DataNameResultrepresents theresultof a specific data name test and is returned byDataNameConvention.validate(). The.is_parsableproperty indicates whether or not the name could be parsed by the DataNameConvention's regex. The.is_validproperty indicates whether or notallof the clauses validate. (.is_validwill always beFalseif.is_parsableisFalse). DataNameResult is anamedtuple.
The values for individual clauses can be directly accessed using dotted property notation (eg  via members such asdnr.datatheme.Descriptionordnr.source.Organisation. Each individual clause will have its own.is_validproperty (eg .dnr.datatheme.is_valid).Example code:dnc = DataNameConvention(path_to_dnc_json_definition)

# regex does not match
dnr = dnc.validate('abcde')
self.assertFalse(dnr.is_parsable)

# regex does matches, but some clauses fail lookup in csv file
dnr = dnc.validate(r'aaa_admn_ad3_py_s0_wfp_pp')

if dnr.is_valid:
	print('the dataname is valid')
else:
	print('the dataname is not valid')
	
# use the `_asdict()` method to loop through all clauses
for clause in dnr._asdict().values():
	clause_details = dni.clause(clause)
	if clause_details:
		print('The extra information associated with clause name {} are {}'.format(clause, clause_details)
	else:
		print('The erroneous value for clause {} was {} '.format(clause, clause_details)

# Use the dnr object in template strings
print('The {dnr.datatheme.Description} data was generously supplied by {dnr.source.Organisation}, downloaded '
	'from {dnr.source.url}'.format(dnr=dnr))Output:The erroneous value for clause `geoext` was `aaa`
Extra information associated with clause `scale`:
    Description = Global mapping
    Scale_range = ? 5 000 000
Extra information associated with clause `freetext`:
    text = None
Extra information associated with clause `perm`:
    Description = Data public - Products public
Extra information associated with clause `source`:
    url =
    Organisation = World Food Program
    admn1PCode =
    admn2Name =
    admn2PCode =
    admn1Name =
Extra information associated with clause `datacat`:
    Description = Admin
Extra information associated with clause `geom`:
    Description = Polygon / area
Extra information associated with clause `datatheme`:
    Category = admn
    Description = Administrative boundary (level 3)


The Administrative boundary (level 3) data was generously supplied by World Food Program, downloaded from https://www.wfp.org/