Fix build-dir not stooping on error, remove build-dir.py

This commit is contained in:
Kenneth Benzie 2018-09-03 11:32:29 +01:00
parent 6a4531423e
commit 2589b63023
2 changed files with 10 additions and 53 deletions

View File

@ -1,46 +0,0 @@
#!/usr/bin/env python
"""The pick_build_dir command selects a build directory
The pick_build_dir command scans the current directory for directories starting
with ``build`` and prompts the user to select one from the list.
"""
from __future__ import print_function
from argparse import ArgumentParser
from os import listdir
from os.path import curdir, isdir
from sys import stderr
from pick import Picker
def main():
"""Main entry point to build-dir.py script."""
parser = ArgumentParser()
parser.add_argument('output')
parser.add_argument('--default', action='store_true')
args = parser.parse_args()
directories = []
for directory in listdir(curdir):
if isdir(directory) and directory.startswith('build'):
directories.append(directory)
if len(directories) == 0:
print('no build directories found', file=stderr)
exit(1)
build_dirs = sorted(directories)
if args.default:
build_dir = build_dirs[0]
else:
picker = Picker(build_dirs, 'Select a build directory:')
picker.register_custom_handler(ord(''), lambda _: exit(1))
build_dir, _ = picker.start()
with open(args.output, 'w') as output:
output.write(build_dir)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
exit(130)

View File

@ -37,15 +37,18 @@ optional arguments:
EOF EOF
return return
fi fi
error() { echo "\e[31merror:\e[0m $1"; return 1 } error() { echo "\e[31merror:\e[0m $1" }
warning() { echo "\e[33mwarning:\e[0m $1" }
local build_dir local build_dir
if [[ ${#*} -gt 1 ]]; then if [[ ${#*} -gt 1 ]]; then
echo $usage echo $usage
error "unexpected position arguments: ${*[2,${#*}]}" error "unexpected position arguments: ${*[2,${#*}]}"; return 1
elif [[ ${#*} -eq 1 ]]; then elif [[ ${#*} -eq 1 ]]; then
if [[ ! -d ${*[1]} ]]; then
warning "directory not found: ${*[1]}"
else
build_dir=${*[1]} build_dir=${*[1]}
[[ ! -d $build_dir ]] && \ fi
error "directory not found: $build_dir"
fi fi
# If <directory> was not set begin selection # If <directory> was not set begin selection
@ -60,7 +63,7 @@ EOF
# Interactively select a build directory if more than 1 found # Interactively select a build directory if more than 1 found
integer index=0 integer index=0
if [[ ${#build_dirs} -eq 0 ]]; then if [[ ${#build_dirs} -eq 0 ]]; then
error "no build directories found" error "no build directories found"; return 1
elif [[ ${#build_dirs} -gt 1 ]]; then elif [[ ${#build_dirs} -gt 1 ]]; then
zmodload zsh/curses && { zmodload zsh/curses && {
# Get the size of the terminal # Get the size of the terminal
@ -139,7 +142,7 @@ EOF
# If the build variable is not defined the command could not be determined # If the build variable is not defined the command could not be determined
if [ -z $build ]; then if [ -z $build ]; then
echo "\e[33mwarning:\e[0m build command detection failed: $build_dir" warning "build command detection failed: $build_dir"
# Prompt user to enter a build command # Prompt user to enter a build command
vared -p 'enter comand: ' build vared -p 'enter comand: ' build
fi fi