summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-05-24 17:52:17 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-05-24 17:52:17 +0200
commit447f17d09268a90c9699a5cb2225dd5c7c11b3b1 (patch)
treeccb3cfec06e3fd084352b7489a9fa7217f159311 /chimere/models.py
parentf27b836d0ae15e7b49db1b53bbd567788d3ca205 (diff)
downloadChimère-447f17d09268a90c9699a5cb2225dd5c7c11b3b1.tar.bz2
Chimère-447f17d09268a90c9699a5cb2225dd5c7c11b3b1.zip
GPX files: manage files with accents
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/chimere/models.py b/chimere/models.py
index d4b3219..7d953cd 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -26,6 +26,8 @@ import json
import os
import pyexiv2
import re
+import tempfile
+import shutil
from lxml import etree
from PIL import Image
@@ -1512,24 +1514,33 @@ class RouteFile(models.Model):
if self.simplified_file:
return
input_name = settings.MEDIA_ROOT + self.raw_file.name
- output_name = settings.MEDIA_ROOT + self.raw_file.name[:-4] + \
- "_simplified" + ".gpx"
+ temp_dir = tempfile.gettempdir()
+ temp_path = os.path.join(temp_dir, 'temp_filename.gpx')
+ temp_out_path = os.path.join(temp_dir, 'temp_out_filename.gpx')
+ shutil.copy2(input_name, temp_path)
+
cli_args = [settings.GPSBABEL, '-i']
if self.file_type == 'K':
cli_args.append('kml')
elif self.file_type == 'G':
cli_args.append('gpx')
- cli_args += ['-f', input_name, '-x', settings.GPSBABEL_OPTIONS,
- '-o', 'gpx', '-F', output_name]
- p = Popen(cli_args, stderr=PIPE)
- p.wait()
- if p.returncode:
- print(p.stderr.read())
- # logger.error(p.stderr.read())
- else:
- self.simplified_file = File(open(output_name))
- self.save()
- os.remove(output_name)
+ cli_args += ['-f', temp_path, '-x',
+ settings.GPSBABEL_OPTIONS, '-o', 'gpx', '-F',
+ temp_out_path]
+ with Popen(cli_args, stderr=PIPE) as p:
+ p.wait()
+ if p.returncode:
+ print(p.stderr.read())
+ # logger.error(p.stderr.read())
+ else:
+ output_name = settings.MEDIA_ROOT + self.raw_file.name[:-4] + \
+ "_simplified" + ".gpx"
+ shutil.copy2(temp_out_path, output_name)
+ self.simplified_file = File(open(output_name))
+ self.save()
+ os.remove(output_name)
+ os.remove(temp_out_path)
+ os.remove(temp_path)
@property
def route(self):