-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
old-commit-hash: dd34ccf
- Loading branch information
Vehicle Researcher
committed
Jun 6, 2019
1 parent
86fb001
commit e47a2e6
Showing
106 changed files
with
3,753 additions
and
1,926 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ selfdrive/visiond/visiond | |
/src/ | ||
|
||
one | ||
openpilot | ||
xx | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from posix.time cimport clock_gettime, timespec, CLOCK_BOOTTIME, CLOCK_MONOTONIC_RAW | ||
|
||
cdef double readclock(int clock_id): | ||
cdef timespec ts | ||
cdef double current | ||
|
||
clock_gettime(clock_id, &ts) | ||
current = ts.tv_sec + (ts.tv_nsec / 1000000000.) | ||
return current | ||
|
||
|
||
def monotonic_time(): | ||
return readclock(CLOCK_MONOTONIC_RAW) | ||
|
||
def sec_since_boot(): | ||
return readclock(CLOCK_BOOTTIME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
from atomicwrites import AtomicWriter | ||
|
||
def mkdirs_exists_ok(path): | ||
try: | ||
os.makedirs(path) | ||
except OSError: | ||
if not os.path.isdir(path): | ||
raise | ||
|
||
def rm_not_exists_ok(path): | ||
try: | ||
os.remove(path) | ||
except OSError: | ||
if os.path.exists(path): | ||
raise | ||
|
||
def rm_tree_or_link(path): | ||
if os.path.islink(path): | ||
os.unlink(path) | ||
elif os.path.isdir(path): | ||
shutil.rmtree(path) | ||
|
||
def get_tmpdir_on_same_filesystem(path): | ||
# TODO(mgraczyk): HACK, we should actually check for which filesystem. | ||
normpath = os.path.normpath(path) | ||
parts = normpath.split("/") | ||
if len(parts) > 1: | ||
if parts[1].startswith("raid"): | ||
if len(parts) > 2 and parts[2] == "runner": | ||
return "/{}/runner/tmp".format(parts[1]) | ||
elif len(parts) > 2 and parts[2] == "aws": | ||
return "/{}/aws/tmp".format(parts[1]) | ||
else: | ||
return "/{}/tmp".format(parts[1]) | ||
elif parts[1] == "aws": | ||
return "/aws/tmp" | ||
elif parts[1] == "scratch": | ||
return "/scratch/tmp" | ||
return "/tmp" | ||
|
||
class AutoMoveTempdir(object): | ||
def __init__(self, target_path, temp_dir=None): | ||
self._target_path = target_path | ||
self._path = tempfile.mkdtemp(dir=temp_dir) | ||
|
||
@property | ||
def name(self): | ||
return self._path | ||
|
||
def close(self): | ||
os.rename(self._path, self._target_path) | ||
|
||
def __enter__(self): return self | ||
|
||
def __exit__(self, type, value, traceback): | ||
if type is None: | ||
self.close() | ||
else: | ||
shutil.rmtree(self._path) | ||
|
||
class NamedTemporaryDir(object): | ||
def __init__(self, temp_dir=None): | ||
self._path = tempfile.mkdtemp(dir=temp_dir) | ||
|
||
@property | ||
def name(self): | ||
return self._path | ||
|
||
def close(self): | ||
shutil.rmtree(self._path) | ||
|
||
def __enter__(self): return self | ||
|
||
def __exit__(self, type, value, traceback): | ||
self.close() | ||
|
||
def _get_fileobject_func(writer, temp_dir): | ||
def _get_fileobject(): | ||
file_obj = writer.get_fileobject(dir=temp_dir) | ||
os.chmod(file_obj.name, 0o644) | ||
return file_obj | ||
return _get_fileobject | ||
|
||
def atomic_write_on_fs_tmp(path, **kwargs): | ||
"""Creates an atomic writer using a temporary file in a temporary directory | ||
on the same filesystem as path. | ||
""" | ||
# TODO(mgraczyk): This use of AtomicWriter relies on implementation details to set the temp | ||
# directory. | ||
writer = AtomicWriter(path, **kwargs) | ||
return writer._open(_get_fileobject_func(writer, get_tmpdir_on_same_filesystem(path))) | ||
|
||
|
||
def atomic_write_in_dir(path, **kwargs): | ||
"""Creates an atomic writer using a temporary file in the same directory | ||
as the destination file. | ||
""" | ||
writer = AtomicWriter(path, **kwargs) | ||
return writer._open(_get_fileobject_func(writer, os.path.dirname(path))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.