-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure config module, user can dynamic set configure values now
Signed-off-by: xcgspring <[email protected]>
- Loading branch information
Showing
26 changed files
with
1,209 additions
and
455 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,97 +1,116 @@ | ||
|
||
import os | ||
|
||
config_section="XML" | ||
default_configs={ "app_map_location": os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "example"), | ||
"schema_location": os.path.join(os.path.dirname(os.path.abspath(__file__)), "schemas"), | ||
"timeout": 5, | ||
"screenshot_location": os.path.dirname(os.path.abspath(__file__)), | ||
"screenshot_on_failure": "False", | ||
} | ||
|
||
AppMapLocation=default_configs["app_map_location"] | ||
SchemaLocation=default_configs["schema_location"] | ||
TimeOut=default_configs["timeout"] | ||
ScreenshotLocation=default_configs["screenshot_location"] | ||
ScreenshotOnFailure=default_configs["screenshot_on_failure"] | ||
|
||
def config(configs=None): | ||
'''call back function used by config module | ||
set the global variables according to configuration | ||
class Config(object): | ||
''' | ||
if configs is None: | ||
configs = default_configs | ||
|
||
global AppMapLocation | ||
global SchemaLocation | ||
global TimeOut | ||
global ScreenshotLocation | ||
global ScreenshotOnFailure | ||
AppMapLocation=configs["app_map_location"] | ||
SchemaLocation=configs["schema_location"] | ||
TimeOut=configs["timeout"] | ||
ScreenshotLocation=configs["screenshot_location"] | ||
ScreenshotOnFailure=configs["screenshot_on_failure"] | ||
|
||
#used by config module | ||
__all__=["config_section", "default_configs", "config"] | ||
|
||
def query_app_map_file(app_map_file): | ||
'''search app_map_file in AppMapLocation, return abs path if found | ||
Arguments: | ||
app_map_file: app_map file name | ||
Returns: | ||
abs_app_map_file: abs path of the app_map file | ||
configs for core module | ||
''' | ||
if os.path.isabs(app_map_file) and os.path.isfile(app_map_file): | ||
return app_map_file | ||
else: | ||
basename = os.path.basename(app_map_file) | ||
for root, dirs, files in os.walk(AppMapLocation): | ||
for file_ in files: | ||
if file_ == basename: | ||
return os.path.join(root, basename) | ||
raise ValueError("%s not found in %s" % (app_map_file, AppMapLocation)) | ||
|
||
def query_schema_file(schema_file): | ||
'''search schema_file in SchemaLocation, return abs path if found | ||
Arguments: | ||
schema_file: schema file name | ||
Returns: | ||
abs_schema_file: abs path of the schema file | ||
''' | ||
if os.path.isabs(schema_file) and os.path.isfile(schema_file): | ||
return schema_file | ||
else: | ||
basename = os.path.basename(schema_file) | ||
for root, dirs, files in os.walk(SchemaLocation): | ||
for file_ in files: | ||
if file_ == basename: | ||
return os.path.join(root, basename) | ||
raise ValueError("%s not found in %s" % (schema_file, SchemaLocation)) | ||
|
||
def query_timeout(): | ||
'''query timeout from config | ||
Return: timeout set in config | ||
''' | ||
return TimeOut | ||
|
||
def query_screenshot_location(): | ||
'''query screenshot_location from config | ||
Return: screenshot_location | ||
''' | ||
if not os.path.isdir(ScreenshotLocation): | ||
os.makedirs(ScreenshotLocation) | ||
|
||
return ScreenshotLocation | ||
|
||
def query_screenshot_on_failure(): | ||
'''query screenshot_on_failure from config | ||
''' | ||
results = {"True":True, "False":False} | ||
|
||
if ScreenshotOnFailure in results: | ||
return results[ScreenshotOnFailure] | ||
else: | ||
#use default | ||
return results[default_configs["screenshot_on_failure"]] | ||
_app_map_location = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "example") | ||
_schema_location = os.path.join(os.path.dirname(os.path.abspath(__file__)), "schemas") | ||
_time_out = 5 | ||
_screenshot_location = os.path.dirname(os.path.abspath(__file__)) | ||
_screenshot_on_failure = False | ||
|
||
def __str__(self): | ||
''' | ||
some help str for this config | ||
''' | ||
pass | ||
|
||
@property | ||
def app_map_location(self): | ||
return self._app_map_location | ||
|
||
@app_map_location.setter | ||
def app_map_location(self, input): | ||
#check if input location exist | ||
if not os.path.isdir(input): | ||
raise ValueError("Expect a valid directory for app_map_location, get %s" % input) | ||
self._app_map_location = input | ||
|
||
@property | ||
def schema_location(self): | ||
return self._schema_location | ||
|
||
@schema_location.setter | ||
def schema_location(self, input): | ||
#check if input location exist | ||
if not os.path.isdir(input): | ||
raise ValueError("Expect a valid directory for schema_location, get %s" % input) | ||
self._schema_location = input | ||
|
||
@property | ||
def time_out(self): | ||
return self._time_out | ||
|
||
@time_out.setter | ||
def time_out(self, input): | ||
#check if input valid | ||
try: | ||
self._time_out = int(input) | ||
except ValueError: | ||
raise ValueError("Expect an int value for global time out, get %s" % input) | ||
|
||
@property | ||
def screenshot_location(self): | ||
return self._screenshot_location | ||
|
||
@screenshot_location.setter | ||
def screenshot_location(self, input): | ||
#check if input valid | ||
if not os.path.isabs(input): | ||
raise ValueError("Expect a path for screenshot_location, get %s" % input) | ||
else: | ||
if not os.path.isdir(input): | ||
os.makedirs(input) | ||
self._screenshot_location = input | ||
|
||
@property | ||
def screenshot_on_failure(self): | ||
return self._screenshot_on_failure | ||
|
||
@screenshot_on_failure.setter | ||
def screenshot_on_failure(self, input): | ||
accepts = {"TRUE": True, "FALSE": False, True: True, False: False} | ||
if input in accepts: | ||
self._screenshot_on_failure = accepts[input] | ||
elif isinstance(input, str) and input.upper() in accepts: | ||
self._screenshot_on_failure = accepts[input.upper()] | ||
else: | ||
raise ValueError("Expect a True/False for screenshot_on_failure, get %s" % input) | ||
|
||
def query_app_map_file(self, app_map_file): | ||
'''search app_map_file in AppMapLocation, return abs path if found | ||
Arguments: | ||
app_map_file: app_map file name | ||
Returns: | ||
abs_app_map_file: abs path of the app_map file | ||
''' | ||
if os.path.isabs(app_map_file) and os.path.isfile(app_map_file): | ||
return app_map_file | ||
else: | ||
basename = os.path.basename(app_map_file) | ||
for root, dirs, files in os.walk(self.app_map_location): | ||
for file_ in files: | ||
if file_ == basename: | ||
return os.path.join(root, basename) | ||
raise ValueError("%s not found in %s" % (app_map_file, self.app_map_location)) | ||
|
||
def query_schema_file(self, schema_file): | ||
'''search schema_file in SchemaLocation, return abs path if found | ||
Arguments: | ||
schema_file: schema file name | ||
Returns: | ||
abs_schema_file: abs path of the schema file | ||
''' | ||
if os.path.isabs(schema_file) and os.path.isfile(schema_file): | ||
return schema_file | ||
else: | ||
basename = os.path.basename(schema_file) | ||
for root, dirs, files in os.walk(self.schema_location): | ||
for file_ in files: | ||
if file_ == basename: | ||
return os.path.join(root, basename) | ||
raise ValueError("%s not found in %s" % (schema_file, self.schema_location)) | ||
|
||
core_config = Config() |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#used by config module | ||
from XML_config import * | ||
from XML_config import core_config | ||
#app map interface | ||
from app_map import AppMap |
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
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
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
Oops, something went wrong.