forked from AlexAltea/codeql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
57 lines (48 loc) · 1.24 KB
/
Copy pathcommon.py
File metadata and controls
57 lines (48 loc) · 1.24 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
CodeQL for Python.
"""
import os
import subprocess
import tempfile
import uuid
# Configuration
codeql_path = 'codeql'
search_path = None
library_path = None
# Temporaries
temp_path = None
def temporary_root():
global temp_path
if temp_path is None:
temp_path = tempfile.TemporaryDirectory(prefix="codeql-python_")
return temp_path.name
def temporary_path(prefix, suffix):
name = ''
if prefix:
name += prefix
name += uuid.uuid4().hex
if suffix:
name += suffix
return os.path.join(temporary_root(), name)
def temporary_dir(create=True, prefix=None, suffix=None):
path = temporary_path(prefix, suffix)
if create:
os.mkdir(path)
return path
def temporary_file(create=True, prefix=None, suffix=None):
path = temporary_path(prefix, suffix)
if create:
open(path, 'a').close()
return path
# Environment
def set_search_path(path):
global search_path
if type(path) == list:
separator = ';' if os.name == 'nt' else ':'
path = separator.join(path)
search_path = path
def run(args):
command = [codeql_path] + list(map(str, args))
return subprocess.run(command, stdout=subprocess.DEVNULL)