[go: up one dir, main page]

Menu

[dfe9bc]: / globals / stage.py  Maximize  Restore  History

Download this file

61 lines (44 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ******************************************************
# * Copyright © 2017-2023 - Jordan Irwin (AntumDeluge) *
# ******************************************************
# * This software is licensed under the MIT license. *
# * See: LICENSE.txt for details. *
# ******************************************************
## @module globals.stage
import os
import shutil
from globals.dateinfo import GetDate
from globals.dateinfo import dtfmt
from libdebreate import appinfo
## Creates a directory for storing temporary files.
#
# @return
# Path to new stage directory, or None if failed.
def CreateStage():
stage = "/tmp"
# Use current working directory if no write access to /tmp
if not os.access(stage, os.W_OK):
stage = os.getcwd()
#suffix = "{}{}{}_".format(GetYear(), GetMonthInt(), GetDayInt())
#suffix = "_temp"
suffix = GetDate(dtfmt.STAMP)
stage = "{}/{}-{}_{}".format(stage, appinfo.getName().lower(), appinfo.getVersionString(), suffix)
if os.access(os.path.dirname(stage), os.W_OK):
# Start with fresh directory
if os.path.isdir(stage):
shutil.rmtree(stage)
elif os.path.isfile(stage):
os.remove(stage)
os.makedirs(stage)
if os.path.isdir(stage):
return stage
## Remove a previously created stage directory.
#
# @param stage
# Absolute path to directory to remove.
# @return
# `True` if stage does not exist.
def RemoveStage(stage):
if os.access(stage, os.W_OK):
shutil.rmtree(stage)
return not os.path.exists(stage)