-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib_django_updater.py
67 lines (59 loc) · 2.25 KB
/
lib_django_updater.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
57
58
59
60
61
62
63
64
65
66
67
import logging
import os
import pprint
import subprocess
from pathlib import Path
log = logging.getLogger(__name__)
def check_for_django_update(incoming_text: str) -> bool:
"""
Checks if incoming diff-text indicates a django update.
Iterates through lines of incoming text.
- first strips whitespace from each line
- then checks if the string '+django==' is in the line
"""
log.info('::: check_for_django_update ----------')
return_val: bool = False
incoming_lines: list = incoming_text.split('\n')
for line in incoming_lines:
line: str = line.strip()
if '+django==' in line:
return_val = True
break
log.info(f'ok / django-updated, ``{return_val}``')
return return_val
def run_collectstatic(project_path: Path) -> None | str:
"""
Runs collectstatic command.
"""
log.info('::: running collectstatic ----------')
log.debug(f'cwd: {os.getcwd()}')
command = ['bash', '-c', 'source ../env/bin/activate && python ./manage.py collectstatic --noinput']
log.debug(f'command: {command}')
subprocess.run(command, check=True)
result: subprocess.CompletedProcess = subprocess.run(command, cwd=str(project_path), capture_output=True, text=True)
log.debug(f'result: {result}')
ok = True if result.returncode == 0 else False
if ok is True:
log.info('ok / collectstatic successful')
problem_message = None
else:
output = {'stdout': f'{result.stdout}', 'stderr': f'{result.stderr}'}
problem_message = f'Problem running collectstatic; output, ``{pprint.pformat(output)}``'
return problem_message
# def run_collectstatic() -> None | str:
# """
# Runs collectstatic command.
# """
# log.info('::: running collectstatic ----------')
# try:
# ## log cwd
# log.debug(f'cwd: {os.getcwd()}')
# command = ['bash', '-c', 'source ../env/bin/activate && python ./manage.py collectstatic --noinput']
# log.debug(f'command: {command}')
# subprocess.run(command, check=True)
# message = None
# except subprocess.CalledProcessError as e:
# message = f'Error running collectstatic: {e}'
# log.exception(message)
# log.debug(f'message: {message}')
# return message