mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
python: Replace os.system with subprocess.call.
Generally, we avoid os.system, since it shells out and thus can be a cause of security issues.
This commit is contained in:
@@ -3,9 +3,9 @@ from __future__ import absolute_import
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from lib.css_parser import parse, CssParserException
|
from lib.css_parser import parse, CssParserException
|
||||||
from typing import Iterable, Text
|
from typing import Iterable, Text
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import glob
|
import glob
|
||||||
|
import subprocess
|
||||||
|
|
||||||
# check for the venv
|
# check for the venv
|
||||||
from lib import sanity_check
|
from lib import sanity_check
|
||||||
@@ -18,7 +18,7 @@ def validate(fn):
|
|||||||
if text != section_list.text():
|
if text != section_list.text():
|
||||||
print('%s seems to be broken:' % (fn,))
|
print('%s seems to be broken:' % (fn,))
|
||||||
open('/var/tmp/pretty_css.txt', 'w').write(section_list.text())
|
open('/var/tmp/pretty_css.txt', 'w').write(section_list.text())
|
||||||
os.system('diff %s /var/tmp/pretty_css.txt' % (fn,))
|
subprocess.call(['diff', fn, '/var/tmp/pretty_css.txt'], stderr=subprocess.STDOUT)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def check_our_files(filenames):
|
def check_our_files(filenames):
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from .template_parser import (
|
|||||||
is_django_block_tag,
|
is_django_block_tag,
|
||||||
)
|
)
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
import os
|
import subprocess
|
||||||
|
|
||||||
def pretty_print_html(html, num_spaces=4):
|
def pretty_print_html(html, num_spaces=4):
|
||||||
# type: (str, int) -> str
|
# type: (str, int) -> str
|
||||||
@@ -181,6 +181,6 @@ def validate_indent_html(fn):
|
|||||||
temp_file.write(phtml)
|
temp_file.write(phtml)
|
||||||
temp_file.close()
|
temp_file.close()
|
||||||
print('Invalid Indentation detected in file: %s\nDiff for the file against expected indented file:' % (fn))
|
print('Invalid Indentation detected in file: %s\nDiff for the file against expected indented file:' % (fn))
|
||||||
os.system('diff %s %s' % (fn, '/var/tmp/pretty_html.txt'))
|
subprocess.call(['diff', fn, '/var/tmp/pretty_html.txt'], stderr=subprocess.STDOUT)
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import sh
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ try:
|
|||||||
sh.git('diff-index', '--cached', '--quiet', 'HEAD')
|
sh.git('diff-index', '--cached', '--quiet', 'HEAD')
|
||||||
except sh.ErrorReturnCode:
|
except sh.ErrorReturnCode:
|
||||||
sys.stderr.write('Your Git repository is not clean!\n\n')
|
sys.stderr.write('Your Git repository is not clean!\n\n')
|
||||||
os.system('git status') # output to terminal
|
subprocess.call(['git', 'status'], stderr=subprocess.STDOUT) # output to terminal
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
with open('tools/print-all/tex/preamble.tex', 'w') as f:
|
with open('tools/print-all/tex/preamble.tex', 'w') as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user