本文整理汇总了Python中safe.common.version.get_version函数的典型用法代码示例。如果您正苦于以下问题:Python get_version函数的具体用法?Python get_version怎么用?Python get_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_version函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_version
def test_get_version(self):
"""Test for get_version."""
version_tuple = ('2', '2', '0', 'alpha', '0')
version = get_version(version_tuple)
if 'win32' in sys.platform or 'darwin' in sys.platform:
expected_version = '2.2.0.dev-master'
message = 'It should be %s but got %s' % (
expected_version, version)
self.assertEqual(expected_version, version, message)
else:
expected_version = '2.2.0.dev-ABCDEFG'
message = 'It should be %s but got %s' % (
expected_version[:9], version[:9])
self.assertEqual(expected_version[:9], version[:9], message)
message = 'Expected version that has length %d, got %d' % (
len(expected_version), len(version))
self.assertEqual(len(expected_version), len(version), message)
# Version tuple doesn't have length == 5
version_tuple = ('2', '2', '0', 'alpha')
self.assertRaises(RuntimeError, get_version, version_tuple)
# Version tuple item 4th is not alpha, beta, rc, final
version_tuple = ('2', '2', '0', 'avocado', '0')
self.assertRaises(RuntimeError, get_version, version_tuple)
# Final version
version_tuple = ('2', '2', '0', 'final', '0')
version = get_version(version_tuple)
self.assertEqual(version, '2.2.0', 'The version should be 2.2.0')
示例2: set_if_provenance
def set_if_provenance(self):
"""Set IF provenance step for the IF."""
data = {
'start_time': self._start_time ,
'finish_time': datetime.now(),
'hazard_layer': self.hazard.keywords['title'],
'exposure_layer': self.exposure.keywords['title'],
'impact_function_id': self.metadata().as_dict()['id'],
'impact_function_version': '1.0', # TODO: Add IF version.
'host_name': self.host_name,
'user': self.user,
'qgis_version': QGis.QGIS_VERSION,
'gdal_version': gdal.__version__,
'qt_version': QT_VERSION_STR,
'pyqt_version': PYQT_VERSION_STR,
'os': platform.version(),
'inasafe_version': get_version(),
# Temporary.
# TODO: Update it later.
'exposure_pixel_size': '',
'hazard_pixel_size': '',
'impact_pixel_size': '',
'analysis_extent': '',
'parameter': ''
}
self.provenance.append_if_provenance_step(
'IF Provenance',
'Impact function\'s provenance.',
timestamp=None,
data=data
)
示例3: download
def download(feature_type, output_base_path, extent, progress_dialog=None):
"""Download shapefiles from Kartoza server.
.. versionadded:: 3.2
:param feature_type: What kind of features should be downloaded.
Currently 'buildings', 'building-points' or 'roads' are supported.
:type feature_type: str
:param output_base_path: The base path of the shape file.
:type output_base_path: str
:param extent: A list in the form [xmin, ymin, xmax, ymax] where all
coordinates provided are in Geographic / EPSG:4326.
:type extent: list
:param progress_dialog: A progress dialog.
:type progress_dialog: QProgressDialog
:raises: ImportDialogError, CanceledImportDialogError
"""
# preparing necessary data
min_longitude = extent[0]
min_latitude = extent[1]
max_longitude = extent[2]
max_latitude = extent[3]
box = (
'{min_longitude},{min_latitude},{max_longitude},'
'{max_latitude}').format(
min_longitude=min_longitude,
min_latitude=min_latitude,
max_longitude=max_longitude,
max_latitude=max_latitude
)
url = (
'{url_osm_prefix}'
'{feature_type}'
'{url_osm_suffix}?'
'bbox={box}&'
'qgis_version={qgis}&'
'lang={lang}&'
'inasafe_version={inasafe_version}'.format(
url_osm_prefix=URL_OSM_PREFIX,
feature_type=feature_type,
url_osm_suffix=URL_OSM_SUFFIX,
box=box,
qgis=qgis_version(),
lang=locale(),
inasafe_version=get_version()))
path = tempfile.mktemp('.shp.zip')
# download and extract it
fetch_zip(url, path, feature_type, progress_dialog)
extract_zip(path, output_base_path)
if progress_dialog:
progress_dialog.done(QDialog.Accepted)
示例4: request
def request(self, request_url):
"""Mock handler for an http request.
:param request_url: Url being requested.
"""
url = str(request_url.url().toString())
reply = MockQNetworkReply()
if url == 'http://hot-export.geofabrik.de/newjob':
reply.content = read_all('test-importdlg-newjob.html')
elif url == 'http://hot-export.geofabrik.de/wizard_area':
reply.content = read_all('test-importdlg-wizardarea.html')
elif url == 'http://hot-export.geofabrik.de/tagupload':
reply.content = read_all('test-importdlg-job.html')
reply._url = 'http://hot-export.geofabrik.de/jobs/1990'
elif url == 'http://hot-export.geofabrik.de/jobs/1990':
reply.content = read_all('test-importdlg-job.html')
elif url == ('http://osm.inasafe.org/buildings-shp?'
'bbox=20.389938354492188,-34.10782492987083'
',20.712661743164062,'
'-34.008273470938335&qgis_version=%s'
'&inasafe_version=%s'
'&lang=en' % (qgis_version(), get_version())):
reply.content = read_all("test-importdlg-extractzip.zip")
return reply
示例5: __init__
def __init__(self, parent=None):
"""Constructor for the dialog.
:param parent: Parent widget of this dialog
:type parent: QWidget
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.setWindowTitle(self.tr('About InaSAFE %s' % get_version()))
self.parent = parent
# Set Limitations Text
limitations_text = ''
for index, limitation in enumerate(limitations()):
limitations_text += '%s. %s \n' % (index + 1, limitation)
self.limitations_text.setFontPointSize(11)
self.limitations_text.setText(limitations_text)
# Set Disclaimer Text
self.disclaimer_text.setFontPointSize(11)
self.disclaimer_text.setText(disclaimer())
# Set Attributions text
image_credits_text = ''
for index, limitation in enumerate(self.attributions()):
image_credits_text += '%s. %s \n' % (index + 1, limitation)
self.image_credits_text.setFontPointSize(11)
self.image_credits_text.setText(image_credits_text)
supporters_path = resources_path('img', 'logos', 'supporters.png')
pixmap = QtGui.QPixmap(supporters_path)
self.supporters_label.setPixmap(pixmap)
示例6: __init__
def __init__(self, parent=None):
"""Constructor for the dialog.
Show the grid converter dialog.
:param parent: parent - widget to use as parent.
:type parent: QWidget
"""
QDialog.__init__(self, parent)
self.parent = parent
self.setupUi(self)
self.setWindowTitle(
self.tr('InaSAFE %s Shakemap Converter' % get_version()))
self.warning_text = set()
self.on_input_path_textChanged()
self.on_output_path_textChanged()
self.update_warning()
# Event register
# noinspection PyUnresolvedReferences
self.use_output_default.toggled.connect(
self.get_output_from_input)
# noinspection PyUnresolvedReferences
self.input_path.textChanged.connect(self.on_input_path_textChanged)
# noinspection PyUnresolvedReferences
self.output_path.textChanged.connect(self.on_output_path_textChanged)
# Set up things for context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
示例7: load_template
def load_template(self):
"""Load the template to composition."""
# Get information for substitutions
# date, time and plugin version
date_time = self._keyword_io.read_keywords(self.layer, "time_stamp")
if date_time is None:
date = ""
time = ""
else:
tokens = date_time.split("_")
date = tokens[0]
time = tokens[1]
long_version = get_version()
tokens = long_version.split(".")
version = "%s.%s.%s" % (tokens[0], tokens[1], tokens[2])
# Get title of the layer
title = self.map_title
if not title:
title = ""
# Prepare the substitution map
substitution_map = {
"impact-title": title,
"date": date,
"time": time,
"safe-version": version,
"disclaimer": self.disclaimer,
}
# Load template
self._template_composition.substitution = substitution_map
try:
self._template_composition.load_template()
except TemplateLoadingError:
raise
示例8: load_template
def load_template(self):
"""Load the template to composition."""
# Get information for substitutions
# date, time and plugin version
date_time = self._keyword_io.read_keywords(self.layer, 'time_stamp')
if date_time is None:
date = ''
time = ''
else:
tokens = date_time.split('_')
date = tokens[0]
time = tokens[1]
long_version = get_version()
tokens = long_version.split('.')
version = '%s.%s.%s' % (tokens[0], tokens[1], tokens[2])
# Get title of the layer
title = self.map_title
if not title:
title = ''
# Prepare the substitution map
substitution_map = {
'impact-title': title,
'date': date,
'time': time,
'safe-version': version,
'disclaimer': self.disclaimer
}
# Load template
self._template_composition.substitution = substitution_map
try:
self._template_composition.load_template()
except TemplateLoadingError:
raise
示例9: __init__
def __init__(self, parent=None):
"""Constructor for the minimum needs dialog.
:param parent: Parent widget of this dialog.
:type parent: QWidget
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.setWindowTitle(self.tr(
'InaSAFE %s Minimum Needs Calculator' % get_version()))
self.polygon_layers_to_combo()
# Set up things for context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
# Fix for issue 1699 - cancel button does nothing
cancel_button = self.button_box.button(QtGui.QDialogButtonBox.Cancel)
cancel_button.clicked.connect(self.reject)
# Fix ends
ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok)
ok_button.clicked.connect(self.accept)
示例10: __init__
def __init__(self, parent=None):
"""Constructor for the dialog.
Show the grid converter dialog.
:param parent: parent - widget to use as parent.
:type parent: QWidget
"""
QDialog.__init__(self, parent)
self.parent = parent
self.setupUi(self)
self.setWindowTitle(
self.tr('InaSAFE %s Shakemap Converter' % get_version()))
self.warning_text = set()
self.on_input_path_textChanged()
self.on_output_path_textChanged()
self.update_warning()
# Event register
# noinspection PyUnresolvedReferences
self.use_output_default.toggled.connect(
self.get_output_from_input)
# noinspection PyUnresolvedReferences
self.input_path.textChanged.connect(self.on_input_path_textChanged)
# noinspection PyUnresolvedReferences
self.output_path.textChanged.connect(self.on_output_path_textChanged)
# Set up things for context help
help_button = self.button_box.button(QDialogButtonBox.Help)
help_button.clicked.connect(ShakemapConverterDialog.show_help)
self.show_info()
示例11: test_provenance_without_aggregation
def test_provenance_without_aggregation(self):
"""Test provenance of impact function without aggregation."""
hazard_layer = load_test_vector_layer(
'gisv4', 'hazard', 'classified_vector.geojson')
exposure_layer = load_test_vector_layer(
'gisv4', 'exposure', 'building-points.geojson')
hazard = definition(hazard_layer.keywords['hazard'])
exposure = definition(exposure_layer.keywords['exposure'])
hazard_category = definition(hazard_layer.keywords['hazard_category'])
expected_provenance = {
'gdal_version': gdal.__version__,
'host_name': gethostname(),
'map_title': get_map_title(hazard, exposure, hazard_category),
'map_legend_title': exposure['layer_legend_title'],
'inasafe_version': get_version(),
'pyqt_version': PYQT_VERSION_STR,
'qgis_version': QGis.QGIS_VERSION,
'qt_version': QT_VERSION_STR,
'user': getpass.getuser(),
'os': readable_os_version(),
'aggregation_layer': None,
'aggregation_layer_id': None,
'exposure_layer': exposure_layer.source(),
'exposure_layer_id': exposure_layer.id(),
'hazard_layer': hazard_layer.source(),
'hazard_layer_id': hazard_layer.id(),
'analysis_question': get_analysis_question(hazard, exposure),
'aggregation_keywords': None,
'exposure_keywords': deepcopy(exposure_layer.keywords),
'hazard_keywords': deepcopy(hazard_layer.keywords),
}
# Set up impact function
impact_function = ImpactFunction()
impact_function.exposure = exposure_layer
impact_function.hazard = hazard_layer
status, message = impact_function.prepare()
self.assertEqual(PREPARE_SUCCESS, status, message)
status, message = impact_function.run()
self.assertEqual(ANALYSIS_SUCCESS, status, message)
self.maxDiff = None
expected_provenance.update({
'action_checklist': impact_function.action_checklist(),
'analysis_extent': impact_function.analysis_extent.exportToWkt(),
'impact_function_name': impact_function.name,
'impact_function_title': impact_function.title,
'notes': impact_function.notes(),
'requested_extent': impact_function.requested_extent,
'data_store_uri': impact_function.datastore.uri_path,
'start_datetime': impact_function.start_datetime,
'end_datetime': impact_function.end_datetime,
'duration': impact_function.duration
})
self.assertDictEqual(expected_provenance, impact_function.provenance)
示例12: download
def download(feature_type, output_base_path, extent, progress_dialog=None):
"""Download shapefiles from Kartoza server.
.. versionadded:: 3.2
:param feature_type: What kind of features should be downloaded.
Currently 'buildings', 'building-points' or 'roads' are supported.
:type feature_type: str
:param output_base_path: The base path of the shape file.
:type output_base_path: str
:param extent: A list in the form [xmin, ymin, xmax, ymax] where all
coordinates provided are in Geographic / EPSG:4326.
:type extent: list
:param progress_dialog: A progress dialog.
:type progress_dialog: QProgressDialog
:raises: ImportDialogError, CanceledImportDialogError
"""
# preparing necessary data
min_longitude = extent[0]
min_latitude = extent[1]
max_longitude = extent[2]
max_latitude = extent[3]
box = (
'{min_longitude},{min_latitude},{max_longitude},'
'{max_latitude}').format(
min_longitude=min_longitude,
min_latitude=min_latitude,
max_longitude=max_longitude,
max_latitude=max_latitude
)
url = URL_OSM_PREFIX + feature_type + URL_OSM_SUFFIX
url = '{url}?bbox={box}&qgis_version={qgis}'.format(
url=url, box=box, qgis=qgis_version())
url += '&inasafe_version=%s' % get_version()
if 'LANG' in os.environ:
# Get the language only : eg 'en_US' -> 'en'
env_lang = os.environ['LANG'].split('_')[0]
url += '&lang=%s' % env_lang
path = tempfile.mktemp('.shp.zip')
# download and extract it
fetch_zip(url, path, feature_type, progress_dialog)
extract_zip(path, output_base_path)
if progress_dialog:
progress_dialog.done(QDialog.Accepted)
示例13: __init__
def __init__(self, parent=None):
"""Constructor for the minimum needs dialog.
:param parent: Parent widget of this dialog.
:type parent: QWidget
"""
QtWidgets.QDialog.__init__(self, parent)
self.setupUi(self)
self.setWindowTitle(self.tr(
'InaSAFE %s Minimum Needs Calculator' % get_version()))
icon = resources_path('img', 'icons', 'show-minimum-needs.svg')
self.setWindowIcon(QtGui.QIcon(icon))
self.result_layer = None
self.button_box.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
# get qgis map layer combobox object
self.layer.setFilters(QgsMapLayerProxyModel.VectorLayer)
# get field that represent displaced count(population)
self.displaced.setFilters(QgsFieldProxyModel.Numeric)
# get field that represent aggregation name
self.aggregation_name.setFilters(QgsFieldProxyModel.String)
# set field to the current selected layer
self.displaced.setLayer(self.layer.currentLayer())
self.aggregation_name.setLayer(self.layer.currentLayer())
self.aggregation_id.setLayer(self.layer.currentLayer())
# link map layer and field combobox
self.layer.layerChanged.connect(self.displaced.setLayer)
self.layer.layerChanged.connect(self.aggregation_name.setLayer)
self.layer.layerChanged.connect(self.aggregation_id.setLayer)
# enable/disable ok button
self.update_button_status()
self.displaced.fieldChanged.connect(self.update_button_status)
# Set up things for context help
self.help_button = self.button_box.button(
QtWidgets.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
# Fix for issue 1699 - cancel button does nothing
cancel_button = self.button_box.button(
QtWidgets.QDialogButtonBox.Cancel)
cancel_button.clicked.connect(self.reject)
# Fix ends
ok_button = self.button_box.button(QtWidgets.QDialogButtonBox.Ok)
ok_button.clicked.connect(self.accept)
示例14: heading
def heading():
"""Helper method that returns just the header.
This method was added so that the text could be reused in the
other contexts.
.. versionadded:: 4.0.0
:returns: A heading object.
:rtype: safe.messaging.heading.Heading
"""
message = m.Heading(
'{} {}'.format(tr('InaSAFE help'), get_version()), **TITLE_STYLE)
return message
示例15: __init__
def __init__(self, iface, dock=None, parent=None):
"""Constructor for the dialog.
:param iface: A Quantum GIS QGisAppInterface instance.
:type iface: QGisAppInterface
:param parent: Parent widget of this dialog
:type parent: QWidget
:param dock: Optional dock widget instance that we can notify of
changes to the keywords.
:type dock: Dock
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version()))
# Save reference to the QGIS interface and parent
self.iface = iface
self.parent = parent
self.dock = dock
self.keyword_io = KeywordIO()
self.defaults = get_defaults()
# Set up things for context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
self.grpNotImplemented.hide()
self.adjustSize()
self.restore_state()
# hack prevent showing use thread visible and set it false see #557
self.cbxUseThread.setChecked(True)
self.cbxUseThread.setVisible(False)
# Set up listener for various UI
self.custom_org_logo_checkbox.toggled.connect(
self.set_organisation_logo)
self.custom_north_arrow_checkbox.toggled.connect(self.set_north_arrow)
self.custom_UseUserDirectory_checkbox.toggled.connect(
self.set_user_dir)
self.custom_templates_dir_checkbox.toggled.connect(
self.set_templates_dir)
self.custom_org_disclaimer_checkbox.toggled.connect(
self.set_org_disclaimer)