本文整理汇总了Python中ngeo_browse_server.config.get_ngeo_config函数的典型用法代码示例。如果您正苦于以下问题:Python get_ngeo_config函数的具体用法?Python get_ngeo_config怎么用?Python get_ngeo_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_ngeo_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_report
def send_report(ip_address=None, begin=None, end=None, access_logfile=None, report_logfile=None, config=None):
config = config or get_ngeo_config()
try:
if not ip_address:
ctrl_config = get_controller_config(get_controller_config_path(config))
ip_address = safe_get(ctrl_config, CONTROLLER_SERVER_SECTION, "address")
except IOError:
# probably no config file present, so IP cannot be determined.
pass
if not ip_address:
raise Exception("IP address could not be determined")
tree = get_report_xml(begin, end, types, access_logfile, report_logfile)
req = urllib2.Request(
url="http://%s/notify" % ip_address,
data=etree.tostring(tree, pretty_print=True),
headers={'Content-Type': 'text/xml'}
)
print req.data
try:
urllib2.urlopen(req, timeout=10)
except (urllib2.HTTPError, urllib2.URLError), e:
logger.error(
"Could not send report (%s): '%s'" % (type(e).__name__, str(e))
)
raise
示例2: handle
def handle(self, *filenames, **kwargs):
System.init()
# parse command arguments
self.verbosity = int(kwargs.get("verbosity", 1))
traceback = kwargs.get("traceback", False)
self.set_up_logging(["ngeo_browse_server"], self.verbosity, traceback)
logger.info("Starting browse layer configuration from command line.")
if not filenames:
raise CommandError("No input files provided.")
on_error = kwargs["on_error"]
config = get_ngeo_config()
no_files_handled_success = 0
no_files_handled_error = 0
# handle each file separately
for filename in filenames:
try:
# handle each browse layer xml
self._handle_file(filename, config)
no_files_handled_success += 1
except Exception, e:
# handle exceptions
no_files_handled_error += 1
logger.error("%s: %s" % (type(e).__name__, str(e)))
if on_error == "continue":
# continue the execution with the next file
continue
elif on_error == "stop":
# re-raise the exception to stop the execution
raise CommandError(e)
示例3: handle
def handle(self, *filenames, **kwargs):
# parse command arguments
self.verbosity = int(kwargs.get("verbosity", 1))
traceback = kwargs.get("traceback", False)
self.set_up_logging(["ngeo_browse_server"], self.verbosity, traceback)
mode = kwargs["mode"]
on_error = kwargs["on_error"]
config = get_ngeo_config()
if not filenames:
raise CommandError("No input files provided.")
# handle each file separately
for filename in filenames:
try:
# handle each browse report
self._handle_file(filename, mode, config)
except Exception, e:
# handle exceptions
if on_error == "continue":
# just print the traceback and continue
self.print_msg("%s: %s" % (type(e).__name__, str(e)), 1, error=True)
continue
elif on_error == "stop":
# re-raise the exception to stop the execution
raise
示例4: unregister
def unregister(instance_id, cs_id, cs_ip, config=None):
config = config or get_ngeo_config()
assert_instance_id(instance_id, config)
try:
with FileLock(get_controller_config_lockfile_path(config)):
controller_config_path = get_controller_config_path(config)
if not exists(controller_config_path):
raise ControllerAssertionError(
"This Browse Server instance was not yet registered.",
reason="UNBOUND"
)
# TODO: controller server ID was removed?
controller_config = get_controller_config(controller_config_path)
assert_controller_id(cs_id, controller_config, "CONTROLLER_OTHER")
assert_controller_ip(cs_ip, controller_config)
# remove the controller configuration to complete unregistration
os.remove(controller_config_path)
except LockException:
raise ControllerAssertionError(
"There is currently another registration in progress.",
reason="CONTROLLER_OTHER"
)
示例5: setUp_files
def setUp_files(self):
# create a temporary storage directory, copy the reference test data
# into it, and point the control.ingest.storage_dir to this location
self.temp_storage_dir = tempfile.mktemp() # create a temp dir
config = get_ngeo_config()
section = "control.ingest"
self.config_filename = tempfile.NamedTemporaryFile(delete=False).name
environ["NGEO_CONFIG_FILE"] = self.config_filename
shutil.copytree(join(settings.PROJECT_DIR, self.storage_dir), self.temp_storage_dir)
config.set(section, "storage_dir", self.temp_storage_dir)
# create a temporary optimized files directory, empty. point the
# control.ingest.optimized_files_dir to it
self.temp_optimized_files_dir = tempfile.mkdtemp()
config.set(section, "optimized_files_dir", self.temp_optimized_files_dir)
self.temp_success_dir = tempfile.mkdtemp()
config.set(section, "success_dir", self.temp_success_dir)
self.temp_failure_dir = tempfile.mkdtemp()
config.set(section, "failure_dir", self.temp_failure_dir)
# copy files to optimized dir
for filename_src, filename_dst in self.copy_to_optimized:
filename_src = join(settings.PROJECT_DIR, "data", filename_src)
filename_dst = join(self.temp_optimized_files_dir, filename_dst)
safe_makedirs(dirname(filename_dst))
shutil.copy(filename_src, filename_dst)
# setup mapcache config/files as retrieved from template
self.temp_mapcache_dir = tempfile.mkdtemp() + "/"
db_file = settings.DATABASES["mapcache"]["TEST_NAME"]
mapcache_config_file = join(self.temp_mapcache_dir, "mapcache.xml")
self.mapcache_config_file = mapcache_config_file
with open(mapcache_config_file, "w+") as f:
f.write(render_to_string("test_control/mapcache.xml",
{"mapcache_dir": self.temp_mapcache_dir,
"mapcache_test_db": db_file,
"browse_layers": models.BrowseLayer.objects.all(),
"base_url": getattr(self, "live_server_url",
"http://localhost/browse")}))
config.set(SEED_SECTION, "config_file", mapcache_config_file)
config.set("mapcache", "tileset_root", self.temp_mapcache_dir)
# setup mapcache dummy seed command
seed_command_file = tempfile.NamedTemporaryFile(delete=False)
seed_command_file.write("#!/bin/sh\nexit 0")
self.seed_command = seed_command_file.name
seed_command_file.close()
st = stat(self.seed_command)
chmod(self.seed_command, st.st_mode | S_IEXEC)
config.set(SEED_SECTION, "seed_command", self.seed_command)
self.temp_status_config = join(tempfile.gettempdir(), "status.conf")
示例6: get_status
def get_status(config=None):
""" Convenience function to return a `Status` object with the global
configuration.
"""
config = config or get_ngeo_config()
return Status(config)
示例7: register
def register(instance_id, instance_type, cs_id, cs_ip, config=None):
config = config or get_ngeo_config()
assert_instance_id(instance_id, config)
assert_instance_type(instance_type)
try:
with FileLock(get_controller_config_lockfile_path(config)):
controller_config_path = get_controller_config_path(config)
if not exists(controller_config_path):
create_controller_config(controller_config_path, cs_id, cs_ip)
else:
controller_config = get_controller_config(
controller_config_path
)
assert_controller_id(cs_id, controller_config, "ALREADY_OTHER")
assert_controller_ip(cs_ip, controller_config)
# IP address and ID are the same, so raise the "ALREADY_SAME"
# error.
raise ControllerAssertionError(
"This browse server is already registered on this "
"controller server.", reason="ALREADY_SAME"
)
except LockException:
raise ControllerAssertionError(
"There is currently another registration in progress.",
reason="ALREADY_OTHER"
)
示例8: ingest_browse
def ingest_browse(parsed_browse, browse_report, browse_layer, preprocessor, crs,
success_dir, failure_dir, seed_areas, config=None):
""" Ingests a single browse report, performs the preprocessing of the data
file and adds the generated browse model to the browse report model. Returns
a boolean value, indicating whether or not the browse has been inserted or
replaced a previous browse entry.
"""
# TODO: if curtain: check that layer allows curtains
# TODO: same for volumes
logger.info("Ingesting browse '%s'."
% (parsed_browse.browse_identifier or "<<no ID>>"))
replaced = False
replaced_extent = None
replaced_filename = None
merge_with = None
merge_footprint = None
config = config or get_ngeo_config()
coverage_id = parsed_browse.browse_identifier
if not coverage_id:
# no identifier given, generate a new one
coverage_id = _generate_coverage_id(parsed_browse, browse_layer)
logger.info("No browse identifier given, generating coverage ID '%s'."
% coverage_id)
else:
try:
models.NCNameValidator(coverage_id)
except ValidationError:
# given ID is not valid, generate a new identifier
old_id = coverage_id
coverage_id = _generate_coverage_id(parsed_browse, browse_layer)
logger.info("Browse ID '%s' is not a valid coverage ID. Using "
"generated ID '%s'." % (old_id, coverage_id))
# get the `leave_original` setting
leave_original = False
try:
leave_original = config.getboolean("control.ingest", "leave_original")
except: pass
# get the input and output filenames
storage_path = get_storage_path()
input_filename = abspath(get_storage_path(parsed_browse.file_name, config=config))
# check that the input filename is valid -> somewhere under the storage dir
if commonprefix((input_filename, storage_path)) != storage_path:
raise IngestionException("Input path '%s' points to an invalid "
"location." % parsed_browse.file_name)
try:
models.FileNameValidator(input_filename)
except ValidationError, e:
raise IngestionException("%s" % str(e), "ValidationError")
示例9: get_configured_log_file_patterns
def get_configured_log_file_patterns(config):
config = config or get_ngeo_config()
items = safe_get(config, CTRL_SECTION, "report_log_files")
if items is None:
return []
return map(get_project_relative_path, items.split(","))
示例10: get_status_config_path
def get_status_config_path(config=None):
""" Returns the configured failure directory. """
config = config or get_ngeo_config()
return get_project_relative_path(
config.get(CTRL_SECTION, "status_config_path", "config/status")
)
示例11: get_failure_dir
def get_failure_dir(config=None):
""" Returns the configured failure directory. """
config = config or get_ngeo_config()
return get_project_relative_path(
safe_get(config, "control.ingest", "failure_dir")
)
示例12: get_ingest_config
def get_ingest_config(config=None):
config = config or get_ngeo_config()
return {
"strategy": safe_get(config, INGEST_SECTION, "strategy", "merge"),
"merge_threshold": parse_time_delta(
safe_get(config, INGEST_SECTION, "merge_threshold", "5h")
)
}
示例13: get_tileset_path
def get_tileset_path(browse_type, config=None):
""" Returns the path to a tileset SQLite file in the `tileset_root` dir. """
config = config or get_ngeo_config()
tileset_root = config.get(MAPCACHE_SECTION, "tileset_root")
tileset = browse_type + ".sqlite" if not browse_type.endswith(".sqlite") else ""
return join(get_project_relative_path(tileset_root), tileset)
示例14: get_values
def get_values(self):
root = read_mapcache_xml(get_ngeo_config())
try:
template = root.xpath("auth_method[1]/template/text()")[0]
baseurl = self.cmd_line_re.match(template).group("url")
except (IndexError, AttributeError):
baseurl = ""
return {"baseurl": baseurl}
示例15: add_mapcache_layer_xml
def add_mapcache_layer_xml(browse_layer, config=None):
name = browse_layer.id
config = config or get_ngeo_config()
root = read_mapcache_xml(config)
if len(root.xpath("cache[@name='%s']|source[@name='%s']|tileset[@name='%s']" % (name, name, name))):
raise Exception(
"Cannot add browse layer to mapcache config, because a layer with "
"the name '%s' is already inserted." % name
)
tileset_path = get_tileset_path(browse_layer.browse_type)
root.extend([
E("cache",
E("dbfile", tileset_path),
E("detect_blank", "true"),
name=name, type="sqlite3"
),
E("source",
E("getmap",
E("params",
E("LAYERS", name),
E("TRANSPARENT", "true")
)
),
E("http",
E("url", "http://localhost/browse/ows?")
),
name=name, type="wms"
),
E("tileset",
E("source", name),
E("cache", name),
E("grid",
URN_TO_GRID[browse_layer.grid], **{
"max-cached-zoom": str(browse_layer.highest_map_level),
"out-of-zoom-strategy": "reassemble"
}
),
E("format", "mixed"),
E("metatile", "8 8"),
E("expires", "3600"),
E("read-only", "true"),
E("timedimension",
E("dbfile", settings.DATABASES["mapcache"]["NAME"]),
E("query", "select strftime('%Y-%m-%dT%H:%M:%SZ',start_time)||'/'||strftime('%Y-%m-%dT%H:%M:%SZ',end_time) from time where source_id=:tileset and start_time<=datetime(:end_timestamp,'unixepoch') and end_time>=datetime(:start_timestamp,'unixepoch') and maxx>=:minx and maxy>=:miny and minx<=:maxx and miny<=:maxy order by end_time desc limit 100"),
type="sqlite", default="2010" # TODO: default year into layer definition
),
name=name
)
])
write_mapcache_xml(root, config)