[buildcore] Add type annotations to pybb
This commit is contained in:
parent
e2b9cd16b3
commit
9394db44b1
23
deps/buildcore/scripts/pybb.py
vendored
23
deps/buildcore/scripts/pybb.py
vendored
@ -17,25 +17,27 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def cat(path):
|
def cat(paths: str) -> int:
|
||||||
|
for path in paths:
|
||||||
try:
|
try:
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
print(data)
|
sys.stdout.write(data)
|
||||||
return 0
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
sys.stderr.write('cat: {}: no such file or directory\n'.format(path))
|
sys.stderr.write('cat: {}: no such file or directory\n'.format(path))
|
||||||
return 1
|
return 1
|
||||||
|
sys.stdout.write('\n')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def mkdir(path):
|
def mkdir(path: str) -> int:
|
||||||
if not os.path.exists(path) and os.path.isdir(path):
|
if not os.path.exists(path) and os.path.isdir(path):
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
# this exists because Windows is utterly incapable of providing a proper rm -rf
|
# this exists because Windows is utterly incapable of providing a proper rm -rf
|
||||||
def rm(path):
|
def rm(path: str) -> int:
|
||||||
if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path):
|
if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path):
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
elif os.path.isdir(path):
|
elif os.path.isdir(path):
|
||||||
@ -43,7 +45,7 @@ def rm(path):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def ctest_all():
|
def ctest_all() -> int:
|
||||||
base_path = sys.argv[2]
|
base_path = sys.argv[2]
|
||||||
if not os.path.isdir(base_path):
|
if not os.path.isdir(base_path):
|
||||||
# no generated projects
|
# no generated projects
|
||||||
@ -58,7 +60,7 @@ def ctest_all():
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def cmake_build(base_path, target):
|
def cmake_build(base_path: str, target: str) -> int:
|
||||||
if not os.path.isdir(base_path):
|
if not os.path.isdir(base_path):
|
||||||
# nothing to build
|
# nothing to build
|
||||||
return 0
|
return 0
|
||||||
@ -73,19 +75,18 @@ def cmake_build(base_path, target):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
err = 0
|
||||||
if sys.argv[1] == 'mkdir':
|
if sys.argv[1] == 'mkdir':
|
||||||
mkdir(sys.argv[2])
|
err = mkdir(sys.argv[2])
|
||||||
elif sys.argv[1] == 'rm':
|
elif sys.argv[1] == 'rm':
|
||||||
for i in range(2, len(sys.argv)):
|
for i in range(2, len(sys.argv)):
|
||||||
rm(sys.argv[i])
|
rm(sys.argv[i])
|
||||||
elif sys.argv[1] == 'ctest-all':
|
elif sys.argv[1] == 'ctest-all':
|
||||||
err = ctest_all()
|
err = ctest_all()
|
||||||
sys.exit(err)
|
|
||||||
elif sys.argv[1] == 'cmake-build':
|
elif sys.argv[1] == 'cmake-build':
|
||||||
err = cmake_build(sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None)
|
err = cmake_build(sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None)
|
||||||
sys.exit(err)
|
|
||||||
elif sys.argv[1] == 'cat':
|
elif sys.argv[1] == 'cat':
|
||||||
err = cat(sys.argv[2])
|
err = cat(sys.argv[2:])
|
||||||
sys.exit(err)
|
sys.exit(err)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user