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