def index(): if request.method == 'POST': datafile = request.files.get('data') metadata = request.files.get('metadata') if not (datafile or metadata): flash('A datafile or FGDC file is required to proceed.', 'danger') return render_template('index.html') fgdc = metadata or StringIO('<metadata/>') if datafile: tmp = tempfile.mkdtemp() filename = os.path.join(tmp, secure_filename(datafile.filename)) datafile.save(filename) try: with closing(datasource(filename)) as ds: metadata = process(fgdc, ds) except BadZipfile: flash('Could not open zipfile.', 'danger') return render_template('index.html') except UnsupportedFormat: flash('Uploaded datafile should be either a zipped shapefile or a GeoTIFF.', 'danger') return render_template('index.html') finally: shutil.rmtree(tmp) else: metadata = process(fgdc) if request.form['access'] == 'restricted': metadata.set_restricted_access() response = make_response(metadata.write()) response.headers['Content-type'] = 'text/xml' response.headers['Content-Disposition'] = \ 'attachment; filename=fgdc.xml' return response return render_template('index.html')
def index(): if request.method == 'POST': datafile = request.files.get('data') metadata = request.files.get('metadata') if not (datafile or metadata): flash('A datafile or FGDC file is required to proceed.', 'danger') return render_template('index.html') fgdc = metadata or StringIO('<metadata/>') if datafile: tmp = tempfile.mkdtemp() filename = os.path.join(tmp, secure_filename(datafile.filename)) datafile.save(filename) try: with closing(datasource(filename)) as ds: metadata = process(fgdc, ds) except BadZipfile: flash('Could not open zipfile.', 'danger') return render_template('index.html') except UnsupportedFormat: flash( 'Uploaded datafile should be either a zipped shapefile or a GeoTIFF.', 'danger') return render_template('index.html') finally: shutil.rmtree(tmp) else: metadata = process(fgdc) if request.form['access'] == 'restricted': metadata.set_restricted_access() response = make_response(metadata.write()) response.headers['Content-type'] = 'text/xml' response.headers['Content-Disposition'] = \ 'attachment; filename=fgdc.xml' return response return render_template('index.html')
def test_process_ensures_elements_exist(shp): r = process(StringIO("<metadata/>"), shp) assert r.doc.find('idinfo/descript/purpose') is not None