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 image_height = 200;
|
||||||
var video_height = 300;
|
var video_height = 300;
|
||||||
var audio_width = 1000;
|
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 AUDIO_TYPES = ["\\.aac", "\\.mp3", "\\.m4a", "\\.ogg", "\\.wav"].join("|");
|
||||||
var VIDEO_TYPES = ["\\.mp4", "\\.m4v", "\\.webm", "\\.ogv"].join("|");
|
var VIDEO_TYPES = ["\\.mp4", "\\.m4v", "\\.webm", "\\.ogv"].join("|");
|
||||||
IMAGE_TYPES = new RegExp(IMAGE_TYPES, "i");
|
IMAGE_TYPES = new RegExp(IMAGE_TYPES, "i");
|
||||||
|
@ -478,8 +478,8 @@ function get_all_urls()
|
||||||
{console.log("Rejecting reddit thumb"); continue;}
|
{console.log("Rejecting reddit thumb"); continue;}
|
||||||
if (url.indexOf("pixel.reddit") != -1 || url.indexOf("reddit.com/static/pixel") != -1)
|
if (url.indexOf("pixel.reddit") != -1 || url.indexOf("reddit.com/static/pixel") != -1)
|
||||||
{console.log("Rejecting reddit pixel"); continue}
|
{console.log("Rejecting reddit pixel"); continue}
|
||||||
/*if (url.indexOf("/thumb/") != -1)
|
if (url.indexOf("/thumb/") != -1)
|
||||||
{console.log("Rejecting /thumb/"); continue;}*/
|
{console.log("Rejecting /thumb/"); continue;}
|
||||||
if (url.indexOf("/loaders/") != -1)
|
if (url.indexOf("/loaders/") != -1)
|
||||||
{console.log("Rejecting loader"); continue;}
|
{console.log("Rejecting loader"); continue;}
|
||||||
if (url.indexOf("memegen") != -1)
|
if (url.indexOf("memegen") != -1)
|
||||||
|
|
|
@ -11,9 +11,10 @@ import string
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
assert len(sys.argv) in (2, 3)
|
assert len(sys.argv) in range(2, 4)
|
||||||
|
|
||||||
ctime = '-c' in sys.argv
|
ctime = '-c' in sys.argv
|
||||||
|
dry = '--dry' in sys.argv
|
||||||
|
|
||||||
IGNORE_EXTENSIONS = ['.py', '.lnk']
|
IGNORE_EXTENSIONS = ['.py', '.lnk']
|
||||||
|
|
||||||
|
@ -56,4 +57,7 @@ for (fileindex, filename) in enumerate(files):
|
||||||
newname = format % (prefix, fileindex, extension)
|
newname = format % (prefix, fileindex, extension)
|
||||||
if os.path.basename(filename) != newname:
|
if os.path.basename(filename) != newname:
|
||||||
print(''.join([c for c in (filename + ' -> ' + newname) if c in string.printable]))
|
print(''.join([c for c in (filename + ' -> ' + newname) if c in string.printable]))
|
||||||
|
if not dry:
|
||||||
os.rename(filename, newname)
|
os.rename(filename, newname)
|
||||||
|
if dry:
|
||||||
|
print('Dry. No files renamed.')
|
|
@ -42,6 +42,8 @@ def fileswith(
|
||||||
for filepath in generator:
|
for filepath in generator:
|
||||||
if not fnmatch.fnmatch(filepath.basename, filepattern):
|
if not fnmatch.fnmatch(filepath.basename, filepattern):
|
||||||
continue
|
continue
|
||||||
|
if not filepath.is_file:
|
||||||
|
continue
|
||||||
handle = open(filepath.absolute_path, 'r', encoding='utf-8')
|
handle = open(filepath.absolute_path, 'r', encoding='utf-8')
|
||||||
matches = []
|
matches = []
|
||||||
try:
|
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 re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from voussoirkit import clipext
|
||||||
|
from voussoirkit import expressionmatch
|
||||||
from voussoirkit import safeprint
|
from voussoirkit import safeprint
|
||||||
from voussoirkit import spinal
|
from voussoirkit import spinal
|
||||||
|
|
||||||
|
@ -11,37 +13,52 @@ def search(
|
||||||
terms,
|
terms,
|
||||||
*,
|
*,
|
||||||
case_sensitive=False,
|
case_sensitive=False,
|
||||||
do_regex=False,
|
do_expression=False,
|
||||||
do_glob=False,
|
do_glob=False,
|
||||||
|
do_regex=False,
|
||||||
inverse=False,
|
inverse=False,
|
||||||
local_only=False,
|
local_only=False,
|
||||||
match_any=False,
|
match_any=False,
|
||||||
|
text=None,
|
||||||
):
|
):
|
||||||
def term_matches(text, term):
|
def term_matches(text, term):
|
||||||
|
if not case_sensitive:
|
||||||
|
text = text.lower()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(term in text) or
|
(term in text) or
|
||||||
(do_regex and re.search(term, 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:
|
if not case_sensitive:
|
||||||
terms = [term.lower() for term in terms]
|
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
|
anyall = any if match_any else all
|
||||||
|
|
||||||
generator = spinal.walk_generator(
|
if text is None:
|
||||||
|
walk = spinal.walk_generator(
|
||||||
depth_first=False,
|
depth_first=False,
|
||||||
recurse=not local_only,
|
recurse=not local_only,
|
||||||
yield_directories=True,
|
yield_directories=True,
|
||||||
)
|
)
|
||||||
for filepath in generator:
|
lines = ((filepath.basename, filepath.absolute_path) for filepath in walk)
|
||||||
basename = filepath.basename
|
else:
|
||||||
if not case_sensitive:
|
lines = text.splitlines()
|
||||||
basename = basename.lower()
|
|
||||||
|
|
||||||
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:
|
if matches ^ inverse:
|
||||||
safeprint.safeprint(filepath.absolute_path)
|
safeprint.safeprint(printout)
|
||||||
|
|
||||||
|
|
||||||
def search_argparse(args):
|
def search_argparse(args):
|
||||||
|
@ -53,6 +70,7 @@ def search_argparse(args):
|
||||||
inverse=args.inverse,
|
inverse=args.inverse,
|
||||||
local_only=args.local_only,
|
local_only=args.local_only,
|
||||||
match_any=args.match_any,
|
match_any=args.match_any,
|
||||||
|
text=args.text if args.text is None else clipext.resolve(args.text),
|
||||||
)
|
)
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
@ -63,8 +81,10 @@ def main(argv):
|
||||||
parser.add_argument('--case', dest='case_sensitive', action='store_true')
|
parser.add_argument('--case', dest='case_sensitive', action='store_true')
|
||||||
parser.add_argument('--regex', dest='do_regex', 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('--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('--local', dest='local_only', action='store_true')
|
||||||
parser.add_argument('--inverse', dest='inverse', 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)
|
parser.set_defaults(func=search_argparse)
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
|
@ -10,9 +10,9 @@ HTML_TREE_HEAD = '''
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
|
||||||
<script type="text/javascript">
|
<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";
|
div.style.display = "none";
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,17 @@ function collapse(div)
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</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 = '''
|
HTML_FORMAT_DIRECTORY = '''
|
||||||
|
|
Loading…
Reference in a new issue