OpenDroneMap-ODM/opendm/system.py

72 wiersze
1.8 KiB
Python
Czysty Zwykły widok Historia

2015-11-19 12:02:30 +00:00
import os
import errno
2015-11-18 16:39:03 +00:00
import json
2015-11-16 14:52:47 +00:00
import datetime
2015-11-26 12:15:02 +00:00
import sys
2015-12-11 21:27:51 +00:00
import subprocess
2015-11-20 10:00:43 +00:00
from opendm import context
2015-11-26 12:15:02 +00:00
from opendm import log
2015-11-18 16:39:03 +00:00
2015-11-18 16:39:03 +00:00
def get_ccd_widths():
"""Return the CCD Width of the camera listed in the JSON defs file."""
with open(context.ccd_widths_path) as jsonFile:
return json.load(jsonFile)
2015-11-16 14:52:47 +00:00
2015-11-16 14:52:47 +00:00
def run(cmd):
"""Run a system command"""
2015-11-26 12:15:02 +00:00
log.ODM_DEBUG('running %s' % cmd)
2015-11-16 14:52:47 +00:00
returnCode = os.system(cmd)
2015-11-26 12:15:02 +00:00
2015-11-16 14:52:47 +00:00
if (returnCode != 0):
2016-03-03 16:31:25 +00:00
log.ODM_ERROR("quitting cause: \n\t" + cmd + "\nreturned with code " +
2015-11-16 14:52:47 +00:00
str(returnCode) + ".\n")
2016-03-03 18:36:04 +00:00
sys.exit('An error occurred. Check stdout above or the logs.')
2015-11-16 14:52:47 +00:00
2015-11-16 14:52:47 +00:00
def now():
"""Return the current time"""
return datetime.datetime.now().strftime('%a %b %d %H:%M:%S %Z %Y')
2016-02-29 14:45:00 +00:00
def now_raw():
return datetime.datetime.now()
def benchmark(start, benchmarking_file, process):
"""
runs a benchmark with a start datetime object
:return: the running time (delta)
"""
# Write to benchmark file
delta = (datetime.datetime.now() - start).total_seconds()
with open(benchmarking_file, 'a') as b:
b.write('%s runtime: %s seconds\n' % (process, delta))
2016-02-29 14:45:00 +00:00
2015-12-10 17:17:39 +00:00
def run_and_return(cmdSrc, cmdDest=None):
2015-11-16 14:52:47 +00:00
"""Run a system command and return the output"""
2015-12-10 17:17:39 +00:00
process = subprocess.Popen(cmdSrc, stdout=subprocess.PIPE, shell=True)
stdout, stderr = process.communicate()
2015-11-16 14:52:47 +00:00
return stdout.decode('ascii')
def mkdir_p(path):
"""Make a directory including parent directories.
"""
2015-11-16 14:52:47 +00:00
try:
os.makedirs(path)
except os.error as exc:
if exc.errno != errno.EEXIST or not os.path.isdir(path):
raise
def calculate_EPSG(utmZone, south):
"""Calculate and return the EPSG"""
if south:
return 32700 + utmZone
else:
return 32600 + utmZone