-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindxml
executable file
·38 lines (33 loc) · 1.43 KB
/
findxml
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# A shell over the linux find command, with colorised output.
#
# A symlink allows a shorter command name without the '*.xml' file extension.
#
# Copyright 2020 by Murray Altheim. All rights reserved. This file is part of
# the Robot Operating System project and is released under the "Apache Licence,
# Version 2.0". Please see the LICENSE file included as part of this package.
#
# author: Murray Altheim
# created: 2020-11-11
# modified: 2021-03-03
#
import os, sys, subprocess
from colorama import init, Fore, Style
init()
if len(sys.argv) != 2:
print(Fore.RED + 'ERROR: expected 1 command line argument: search term.' + Style.RESET_ALL)
sys.exit(1)
term = sys.argv[1]
print(Fore.CYAN + Style.DIM + '-- searching for \"{}\"...'.format(term) + Style.RESET_ALL)
command = 'find . -name "*.xml" -exec grep -H \"{}\" {{}} \;'.format(term)
print(Fore.CYAN + Style.DIM + '-- command: \"{}\"...\n'.format(command) + Style.RESET_ALL)
proc = subprocess.Popen([command], stdout=subprocess.PIPE,universal_newlines=True, shell=True)
count = 0
for line in proc.stdout:
count += 1
_line = str(line).strip()
info = _line.split(':', 1)
print(Fore.CYAN + Style.NORMAL + '{}'.format(info[0]) + ( ' '*(24-len(info[0])) ) + ' :' + Fore.WHITE + Style.BRIGHT + ' {}'.format(info[1]) + Style.RESET_ALL)
print(Fore.CYAN + Style.DIM + '\n-- complete: {:d} instances found.'.format(count) + Style.RESET_ALL)