else
This commit is contained in:
parent
ffb4812112
commit
ece215dfc1
6 changed files with 67 additions and 20 deletions
|
@ -8,7 +8,7 @@ var seen_urls = new Set();
|
|||
var image_height = 200;
|
||||
var video_height = 300;
|
||||
var audio_width = 1000;
|
||||
var IMAGE_TYPES = ["\\.jpg", "\\.jpeg", "\\.jpg", "\\.bmp", "\\.tiff", "\\.tif", "\\.bmp", "\\.gif", "\\.png"].join("|");
|
||||
var IMAGE_TYPES = ["\\.jpg", "\\.jpeg", "\\.jpg", "\\.bmp", "\\.tiff", "\\.tif", "\\.bmp", "\\.gif", "\\.png", "reddituploads\.com"].join("|");
|
||||
var AUDIO_TYPES = ["\\.aac", "\\.mp3", "\\.m4a", "\\.ogg", "\\.wav"].join("|");
|
||||
var VIDEO_TYPES = ["\\.mp4", "\\.m4v", "\\.webm", "\\.ogv"].join("|");
|
||||
IMAGE_TYPES = new RegExp(IMAGE_TYPES, "i");
|
||||
|
@ -478,8 +478,8 @@ function get_all_urls()
|
|||
{console.log("Rejecting reddit thumb"); continue;}
|
||||
if (url.indexOf("pixel.reddit") != -1 || url.indexOf("reddit.com/static/pixel") != -1)
|
||||
{console.log("Rejecting reddit pixel"); continue}
|
||||
/*if (url.indexOf("/thumb/") != -1)
|
||||
{console.log("Rejecting /thumb/"); continue;}*/
|
||||
if (url.indexOf("/thumb/") != -1)
|
||||
{console.log("Rejecting /thumb/"); continue;}
|
||||
if (url.indexOf("/loaders/") != -1)
|
||||
{console.log("Rejecting loader"); continue;}
|
||||
if (url.indexOf("memegen") != -1)
|
||||
|
|
|
@ -11,9 +11,10 @@ import string
|
|||
import re
|
||||
import sys
|
||||
|
||||
assert len(sys.argv) in (2, 3)
|
||||
assert len(sys.argv) in range(2, 4)
|
||||
|
||||
ctime = '-c' in sys.argv
|
||||
dry = '--dry' in sys.argv
|
||||
|
||||
IGNORE_EXTENSIONS = ['.py', '.lnk']
|
||||
|
||||
|
@ -56,4 +57,7 @@ for (fileindex, filename) in enumerate(files):
|
|||
newname = format % (prefix, fileindex, extension)
|
||||
if os.path.basename(filename) != newname:
|
||||
print(''.join([c for c in (filename + ' -> ' + newname) if c in string.printable]))
|
||||
os.rename(filename, newname)
|
||||
if not dry:
|
||||
os.rename(filename, newname)
|
||||
if dry:
|
||||
print('Dry. No files renamed.')
|
|
@ -42,6 +42,8 @@ def fileswith(
|
|||
for filepath in generator:
|
||||
if not fnmatch.fnmatch(filepath.basename, filepattern):
|
||||
continue
|
||||
if not filepath.is_file:
|
||||
continue
|
||||
handle = open(filepath.absolute_path, 'r', encoding='utf-8')
|
||||
matches = []
|
||||
try:
|
||||
|
|
10
Toolbox/linenumbers.py
Normal file
10
Toolbox/linenumbers.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
import sys
|
||||
|
||||
from voussoirkit import clipext
|
||||
|
||||
text = clipext.resolve(sys.argv[1])
|
||||
lines = text.splitlines()
|
||||
digits = len(str(len(lines)))
|
||||
form = '{no:>0%d} | {line}' % digits
|
||||
for (index, line) in enumerate(lines):
|
||||
print(form.format(no=index+1, line=line))
|
|
@ -4,6 +4,8 @@ import os
|
|||
import re
|
||||
import sys
|
||||
|
||||
from voussoirkit import clipext
|
||||
from voussoirkit import expressionmatch
|
||||
from voussoirkit import safeprint
|
||||
from voussoirkit import spinal
|
||||
|
||||
|
@ -11,37 +13,52 @@ def search(
|
|||
terms,
|
||||
*,
|
||||
case_sensitive=False,
|
||||
do_regex=False,
|
||||
do_expression=False,
|
||||
do_glob=False,
|
||||
do_regex=False,
|
||||
inverse=False,
|
||||
local_only=False,
|
||||
match_any=False,
|
||||
text=None,
|
||||
):
|
||||
def term_matches(text, term):
|
||||
if not case_sensitive:
|
||||
text = text.lower()
|
||||
|
||||
return (
|
||||
(term in text) or
|
||||
(do_regex and re.search(term, text)) or
|
||||
(do_glob and fnmatch.fnmatch(text, term))
|
||||
(do_glob and fnmatch.fnmatch(text, term)) or
|
||||
(do_expression and term.evaluate(text))
|
||||
)
|
||||
|
||||
if not case_sensitive:
|
||||
terms = [term.lower() for term in terms]
|
||||
|
||||
if do_expression:
|
||||
terms = ' '.join(terms)
|
||||
terms = [expressionmatch.ExpressionTree.parse(terms)]
|
||||
|
||||
anyall = any if match_any else all
|
||||
|
||||
generator = spinal.walk_generator(
|
||||
depth_first=False,
|
||||
recurse=not local_only,
|
||||
yield_directories=True,
|
||||
)
|
||||
for filepath in generator:
|
||||
basename = filepath.basename
|
||||
if not case_sensitive:
|
||||
basename = basename.lower()
|
||||
if text is None:
|
||||
walk = spinal.walk_generator(
|
||||
depth_first=False,
|
||||
recurse=not local_only,
|
||||
yield_directories=True,
|
||||
)
|
||||
lines = ((filepath.basename, filepath.absolute_path) for filepath in walk)
|
||||
else:
|
||||
lines = text.splitlines()
|
||||
|
||||
matches = anyall(term_matches(basename, term) for term in terms)
|
||||
for line in lines:
|
||||
if isinstance(line, tuple):
|
||||
(line, printout) = line
|
||||
else:
|
||||
printout = line
|
||||
matches = anyall(term_matches(line, term) for term in terms)
|
||||
if matches ^ inverse:
|
||||
safeprint.safeprint(filepath.absolute_path)
|
||||
safeprint.safeprint(printout)
|
||||
|
||||
|
||||
def search_argparse(args):
|
||||
|
@ -53,6 +70,7 @@ def search_argparse(args):
|
|||
inverse=args.inverse,
|
||||
local_only=args.local_only,
|
||||
match_any=args.match_any,
|
||||
text=args.text if args.text is None else clipext.resolve(args.text),
|
||||
)
|
||||
|
||||
def main(argv):
|
||||
|
@ -63,8 +81,10 @@ def main(argv):
|
|||
parser.add_argument('--case', dest='case_sensitive', action='store_true')
|
||||
parser.add_argument('--regex', dest='do_regex', action='store_true')
|
||||
parser.add_argument('--glob', dest='do_glob', action='store_true')
|
||||
parser.add_argument('--expression', dest='do_expression', action='store_true')
|
||||
parser.add_argument('--local', dest='local_only', action='store_true')
|
||||
parser.add_argument('--inverse', dest='inverse', action='store_true')
|
||||
parser.add_argument('--text', dest='text', default=None)
|
||||
parser.set_defaults(func=search_argparse)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
|
|
@ -10,9 +10,9 @@ HTML_TREE_HEAD = '''
|
|||
<meta charset="UTF-8">
|
||||
|
||||
<script type="text/javascript">
|
||||
function collapse(div)
|
||||
function collapse(div, force)
|
||||
{
|
||||
if (div.style.display != "none")
|
||||
if (force !== "block" && div.style.display != "none")
|
||||
{
|
||||
div.style.display = "none";
|
||||
}
|
||||
|
@ -49,6 +49,17 @@ function collapse(div)
|
|||
}
|
||||
</style>
|
||||
</head>
|
||||
<script type="text/javascript">
|
||||
function open_all()
|
||||
{
|
||||
var divs = document.getElementsByTagName("div");
|
||||
for (var index = 0; index < divs.length; index += 1)
|
||||
{
|
||||
collapse(divs[index], "block");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<button onclick="open_all()">Expand all</button>
|
||||
'''
|
||||
|
||||
HTML_FORMAT_DIRECTORY = '''
|
||||
|
|
Loading…
Reference in a new issue