From 08afb75e1fe36d4490e2483029be705b5db44c20 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 16 Mar 2023 19:40:53 +0800 Subject: [PATCH] feat: disable static builds for non-root user --- src/release/release.py | 10 +++++----- src/release/utils/common.py | 4 ++++ src/release/utils/release.py | 9 ++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/release/release.py b/src/release/release.py index e369a8a..93962a2 100755 --- a/src/release/release.py +++ b/src/release/release.py @@ -11,8 +11,8 @@ from utils import gitbookRelease metadata, content = loadBook('rc-5') -txtRelease(metadata, content) -jsonRelease(metadata, content) -htmlRelease(metadata, content) -# staticRelease(metadata, content) -gitbookRelease(metadata, content) +# txtRelease(metadata, content) +# jsonRelease(metadata, content) +# htmlRelease(metadata, content) +staticRelease(metadata, content) +# gitbookRelease(metadata, content) diff --git a/src/release/utils/common.py b/src/release/utils/common.py index 192b97d..f457f5e 100644 --- a/src/release/utils/common.py +++ b/src/release/utils/common.py @@ -39,6 +39,10 @@ resourceInfo = { # resource download links } +def isRoot() -> bool: # whether the current user is root + return os.geteuid() == 0 + + def createFolder(folderName: str) -> None: # create folder if not os.path.exists(folderName): os.mkdir(folderName) diff --git a/src/release/utils/release.py b/src/release/utils/release.py index 4552f7d..c1b66a6 100644 --- a/src/release/utils/release.py +++ b/src/release/utils/release.py @@ -7,6 +7,7 @@ import shutil import tempfile import subprocess +from .common import isRoot from .common import rootPath from .common import saveFile from .common import projectUrl @@ -107,13 +108,11 @@ def staticBuild(workDir: str) -> None: def staticRelease(metadata: dict, content: dict) -> None: - - # TODO: confirm running under root - + if not isRoot(): + print('\033[0;33mDue to the permission problems, it is recommended to run under root user.\033[0m') + return tempDir = tempfile.TemporaryDirectory() # access temporary directory - content = {x: content[x] for x in list(content)[:20]} # TODO: just for test - staticDepends(tempDir.name, metadata, content) staticBuild(tempDir.name) tempDir.cleanup()