mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
email: Code cleanup
- Move render_tabs into plinth.views - Move admin_tabs and user_tabs into the class - New interproc module contains inter-process functions - New helper methods in TabMixin
This commit is contained in:
1 parent
e454e8ac1b
commit
85c6b91fbc
10 files changed
+113
-94
No files matched your search
@@ -0,0 +1,39 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def log_subprocess(result):
|
||||
logger.critical('Subprocess returned %d', result.returncode)
|
||||
logger.critical('Stdout: %r', result.stdout)
|
||||
logger.critical('Stderr: %r', result.stderr)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def atomically_rewrite(filepath):
|
||||
successful = False
|
||||
tmp = '%s.%s.plinth-tmp' % (filepath, uuid.uuid4().hex)
|
||||
fd = open(tmp, 'x')
|
||||
|
||||
try:
|
||||
# Let client write to a temporary file
|
||||
yield fd
|
||||
successful = True
|
||||
finally:
|
||||
fd.close()
|
||||
|
||||
try:
|
||||
if successful:
|
||||
# Invoke rename(2) to atomically replace the original
|
||||
os.rename(tmp, filepath)
|
||||
finally:
|
||||
# Delete temp file
|
||||
try:
|
||||
os.unlink(tmp)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
Reference in new issue
Block a user