-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
const file previously not included in the git repo. That is interesti…
…ng, as it is required in the code. Someone building from repo would have not received this file. Needed for use in the CI pipeline / tests.
- Loading branch information
1 parent
33cec7b
commit ec61189
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
################################################################################ | ||
# | ||
# Copyright 2015 Crown copyright (c) | ||
# Land Information New Zealand and the New Zealand Government. | ||
# All rights reserved | ||
# | ||
# This program is released under the terms of the 3 clause BSD license. See the | ||
# LICENSE file for more information. | ||
# | ||
################################################################################ | ||
|
||
# NOTE | ||
# This is potentially quite a dangerous way to set constants since it overwrites sys.modules and deletes the builtins. | ||
# To prevent this we have to hold a _ref to sys to keep it from being deleted | ||
|
||
import sys | ||
from AIMSDataManager.Config import ConfigReader | ||
|
||
class const: | ||
'''Const class that reads config stored values and presents them as constant values that can be imported''' | ||
|
||
class ConstError(TypeError): pass | ||
|
||
def __init__(self): | ||
'''Initialises and sets sel attributes from configreader values in 'const' section''' | ||
CR = ConfigReader() | ||
for key in CR.configSectionMap('const'): | ||
val = CR.configSectionMap('const')[key] | ||
setattr(self, key.upper(), val) | ||
|
||
def __setattr__(self,name,value): | ||
'''Overriding setattr method catching overwrites | ||
@param name: Attribute name | ||
@param value: Attribute value | ||
''' | ||
if self.__dict__.get(name): | ||
raise self.ConstError('Can\'t rebind const {}'.format(name)) | ||
self.__dict__[name]=value | ||
|
||
#sys.modules overwritten here but _ref holding builtins | ||
_ref, sys.modules[__name__] = sys.modules[__name__], const() |