py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-08-02 03:00:12 +02:00
|
|
|
from lib.html_grep import grep
|
2017-09-30 08:42:22 +02:00
|
|
|
import argparse
|
2016-08-02 03:00:12 +02:00
|
|
|
import sys
|
|
|
|
|
2017-03-03 19:01:52 +01:00
|
|
|
from typing import List
|
2017-02-05 21:24:28 +01:00
|
|
|
|
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
|
|
|
import lister
|
2016-08-02 03:00:12 +02:00
|
|
|
|
|
|
|
USAGE = '''
|
|
|
|
This file greps HTML files for keywords in a context-sensitive manner.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
$ ./tools/html-grep '#group-pms' '.filters'
|
2017-03-01 18:02:15 +01:00
|
|
|
templates/zerver/right_sidebar.html 45
|
2016-08-02 03:00:12 +02:00
|
|
|
|
|
|
|
div.right-sidebar#right-sidebar
|
|
|
|
div#group-pm-list
|
|
|
|
ul.filters.scrolling_list#group-pms
|
|
|
|
|
|
|
|
Keyword syntax:
|
|
|
|
|
|
|
|
When supplying keywords, they must correspond to HTML elements,
|
|
|
|
classes, or ids. Typical keywords are:
|
|
|
|
|
|
|
|
li // search for "<li>"
|
|
|
|
'.modal' // search for '<foo class="modal">'
|
|
|
|
'#intro' // search for '<bar id="intro">'
|
|
|
|
|
|
|
|
Searches are context-sensitive in the sense that the keyword
|
|
|
|
may be found among parent tags of a leaf tag, not just the leaf
|
|
|
|
tag itself. (Think of this as being similar to the way a
|
|
|
|
browser applies nested CSS styles; it looks at the whole HTML
|
|
|
|
tree.)
|
|
|
|
|
|
|
|
Finding files to search:
|
|
|
|
|
|
|
|
The tool currently searches your git repo for files with
|
|
|
|
the extension .html or .handlebars., and then it does
|
|
|
|
the grep against all those files.
|
|
|
|
|
2017-09-30 08:42:22 +02:00
|
|
|
TODO: allow specific files to be searched.'''
|
2016-08-02 03:00:12 +02:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def check_our_files():
|
|
|
|
# type: () -> None
|
2016-08-02 03:00:12 +02:00
|
|
|
|
2017-09-30 08:42:22 +02:00
|
|
|
parser = argparse.ArgumentParser(description=USAGE,
|
|
|
|
formatter_class=argparse.RawTextHelpFormatter)
|
|
|
|
parser.add_argument('--modified', '-m',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='Only check modified files')
|
|
|
|
parser.add_argument('--no-filter', '-a',
|
|
|
|
dest='show_all',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='Show all HTML files (no filtering)')
|
|
|
|
parser.add_argument("keyword", nargs="*", help='keyword to be searched')
|
|
|
|
options = parser.parse_args()
|
2016-08-02 03:00:12 +02:00
|
|
|
|
|
|
|
if options.show_all:
|
2017-05-17 22:49:54 +02:00
|
|
|
keywords = [] # type: List[str]
|
2016-08-02 03:00:12 +02:00
|
|
|
else:
|
2017-09-30 08:42:22 +02:00
|
|
|
if not options.keyword:
|
2016-08-02 03:00:12 +02:00
|
|
|
print('No keywords specified...try --help or --no-filter')
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2017-09-30 08:42:22 +02:00
|
|
|
keywords = options.keyword
|
2016-08-02 03:00:12 +02:00
|
|
|
|
|
|
|
files = lister.list_files(
|
|
|
|
modified_only=options.modified,
|
|
|
|
ftypes=['handlebars', 'html'],
|
|
|
|
)
|
|
|
|
|
2017-01-24 06:08:52 +01:00
|
|
|
fns = [fn for fn in files if ('casperjs' not in fn) and ('puppet/zulip' not in fn)]
|
2016-08-02 03:00:12 +02:00
|
|
|
grep(fns, set(keywords))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
check_our_files()
|