-
Notifications
You must be signed in to change notification settings - Fork 1
/
static_methods.py
56 lines (48 loc) · 1.55 KB
/
static_methods.py
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
"""Static utility functions."""
# from subprocess import PIPE, Popen
# import shlex
import os
import platform
from werkzeug.utils import secure_filename
basedir = os.path.abspath(os.path.dirname(__file__))
path_char = '\\' if platform.system() == 'Windows' else '/'
# def _build_cli_command(target_file, source_file_names, outpath):
# """Build CLI command."""
# command = 'python -m pmix.borrow ' + \
# '--merge ' + target_file + ' ' + \
# '--outpath ' + outpath + \
# source_file_names
# return command
#
#
# def _run_background_process(command_line):
# """This method runs external program using command line interface.
#
# Returns:
# stdout,stdin: Of executed program.
# """
#
# args = shlex.split(command_line, posix=False)
# # process = run(args, stdout=PIPE, stderr=PIPE, shell=True, check=True)
# # stdout = process.stdout
# # stderr = process.stderr
#
# process = Popen(args, stdout=PIPE, stderr=PIPE)
# process.wait()
# stdout = process.stdout.read().decode().strip()
# stderr = process.stderr.read().decode().strip()
#
# return stdout, stderr
def upload_file(file):
"""Upload a file."""
filename = secure_filename(file.filename)
upload_folder = basedir + path_char + 'temp_uploads'
file_path = os.path.join(upload_folder, filename)
if os.path.exists(file_path):
os.remove(file_path)
try:
file.save(file_path)
except FileNotFoundError:
os.mkdir(upload_folder)
file.save(file_path)
return file_path