mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 06:33:57 +08:00
* framework for updates * File caching * update .gitignore * update .gitignore * Store in home tmp directory * fix bugs in old code, add tests * add test * revert bug * Fixed some bugs, more testing * doing some style fixes * Update caching with lenghts * doing some style fixes * doing some style fixes * doing some style fixes * subrepositories * try to fix the tests * change submodules back * doing some style fixes * if we don't cache, we don't cache length either * fix curls * make sure tests run in ci * Cleanup tests * Use int for cache flag * fix linter Co-authored-by: Willem Melching <willem.melching@gmail.com>
27 lines
640 B
Python
27 lines
640 B
Python
import os
|
|
from atomicwrites import AtomicWriter
|
|
|
|
|
|
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)))
|
|
|
|
|
|
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 mkdirs_exists_ok(path):
|
|
try:
|
|
os.makedirs(path)
|
|
except OSError:
|
|
if not os.path.isdir(path):
|
|
raise
|