From 09feecc3cb993bf2d02cb17e53ff5f75712ddf2e Mon Sep 17 00:00:00 2001 From: "benjamin.jakimow" <benjamin.jakimow@geo.hu-berlin.de> Date: Fri, 21 Sep 2018 14:00:56 +0200 Subject: [PATCH] fixed some regexes --- make/make.py | 37 +++++++++++++++++++----------------- timeseriesviewer/__init__.py | 2 +- timeseriesviewer/sandbox.py | 4 ++-- timeseriesviewer/utils.py | 8 ++++---- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/make/make.py b/make/make.py index dae0233f..7b4350fc 100644 --- a/make/make.py +++ b/make/make.py @@ -11,7 +11,7 @@ from PyQt5.QtSvg import * from PyQt5.QtXml import * -import gdal +from osgeo import gdal from timeseriesviewer import DIR_UI, DIR_REPO from timeseriesviewer.utils import file_search, jp @@ -43,7 +43,7 @@ def createFilePackage(dirData, recursive=True): code.append('# '+comment) for f in files: an, ext = os.path.splitext(os.path.basename(f)) - if re.search('^\d', an): + if re.search(r'^\d', an): an = numberPrefix+an an = re.sub(r'[-.]', '_',an) @@ -53,8 +53,8 @@ def createFilePackage(dirData, recursive=True): filePathAttributes.add(an) code.append('\n') - raster = [f for f in files if re.search('.*\.(bsq|bip|bil|tif|tiff)$', f)] - vector = [f for f in files if re.search('.*\.(shp|kml|kmz)$', f)] + raster = [f for f in files if re.search(r'.*\.(bsq|bip|bil|tif|tiff)$', f)] + vector = [f for f in files if re.search(r'.*\.(shp|kml|kmz)$', f)] addFiles(raster, 'Raster files:', numberPrefix='Img_') addFiles(vector, 'Vector files:', numberPrefix='Shp_') @@ -184,7 +184,7 @@ def compile_rc_files(ROOT, targetDir=None): qrcs = set() doc = QDomDocument() - reg = re.compile('(?<=resource=")[^"]+\.qrc(?=")') + reg = re.compile(r'(?<=resource=")[^"]+\.qrc(?=")') for ui_file in ui_files: pathDir = os.path.dirname(ui_file) @@ -448,10 +448,12 @@ def updateMetadataTxt(): import timeseriesviewer, collections md = collections.OrderedDict() - for line in open(pathDst).readlines(): - parts = line.split('=') - if len(parts) >= 2: - md[parts[0]] = '='.join(parts[1:]) + + with open(pathDst) as f: + for line in f.readlines(): + parts = line.split('=') + if len(parts) >= 2: + md[parts[0]] = '='.join(parts[1:]) #update/set new metadata md['name'] = timeseriesviewer.TITLE @@ -464,10 +466,10 @@ def updateMetadataTxt(): md['email'] = "benjamin.jakimow@geo.hu-berlin.de" #md['changelog'] = - f = open(pathAboutPlugin, 'r', encoding='utf-8') - aboutText =f.read() - aboutText=aboutText.replace('\n','') - f.close() + with open(pathAboutPlugin, 'r', encoding='utf-8') as f: + aboutText =f.read() + aboutText=aboutText.replace('\n','') + md['about'] = aboutText md['experimental'] = "False" @@ -482,10 +484,11 @@ def updateMetadataTxt(): lines = ['[general]'] for k, line in md.items(): lines.append('{}={}'.format(k, line)) - f = open(pathDst, 'w', encoding='utf-8') - f.writelines('\n'.join(lines)) - f.flush() - f.close() + + with open(pathDst, 'w', encoding='utf-8') as f: + f.writelines('\n'.join(lines)) + f.flush() + def make_pb_tool_cfg(): diff --git a/timeseriesviewer/__init__.py b/timeseriesviewer/__init__.py index bcdce712..c118aed1 100644 --- a/timeseriesviewer/__init__.py +++ b/timeseriesviewer/__init__.py @@ -23,7 +23,7 @@ import os, sys, fnmatch, site, re, site -VERSION = '0.7.201806201143' +VERSION = '0.7.201809211358' LICENSE = 'GNU GPL-3' TITLE = 'EO Time Series Viewer' DESCRIPTION = 'Visualization of multi-sensor Earth observation time series data.' diff --git a/timeseriesviewer/sandbox.py b/timeseriesviewer/sandbox.py index 42330931..a3a75cc3 100644 --- a/timeseriesviewer/sandbox.py +++ b/timeseriesviewer/sandbox.py @@ -350,9 +350,9 @@ if __name__ == '__main__': #run tests if False: gdal_qgis_benchmark() if False: sandboxQgisBridge() - if False: sandboxGui() + if True: sandboxGui() - if True: sandboxTestdata() + if False: sandboxTestdata() if False: sandboxDemo() #close QGIS qgsApp.exec_() diff --git a/timeseriesviewer/utils.py b/timeseriesviewer/utils.py index 8e1cc2ac..60040ed2 100644 --- a/timeseriesviewer/utils.py +++ b/timeseriesviewer/utils.py @@ -707,7 +707,7 @@ def defaultBands(dataset): db = dataset.GetMetadataItem(str('default_bands'), str('ENVI')) if db != None: - db = [int(n) for n in re.findall('\d+')] + db = [int(n) for n in re.findall(r'\d+')] return db db = [0, 0, 0] cis = [gdal.GCI_RedBand, gdal.GCI_GreenBand, gdal.GCI_BlueBand] @@ -833,10 +833,10 @@ def parseWavelength(dataset): for key, values in mdDict.items(): key = key.lower() - if re.search('wavelength$', key, re.I): - tmp = re.findall('\d*\.\d+|\d+', values) # find floats + if re.search(r'wavelength$', key, re.I): + tmp = re.findall(r'\d*\.\d+|\d+', values) # find floats if len(tmp) != dataset.RasterCount: - tmp = re.findall('\d+', values) # find integers + tmp = re.findall(r'\d+', values) # find integers if len(tmp) == dataset.RasterCount: wl = np.asarray([float(w) for w in tmp]) -- GitLab