markup: move functionality to library
This commit is contained in:
49
markup/work/test_all.py
Executable file
49
markup/work/test_all.py
Executable file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(currentdir)
|
||||
parentparentdir = os.path.dirname(parentdir)
|
||||
sys.path.insert(0, parentparentdir)
|
||||
|
||||
import dumper
|
||||
import getopt
|
||||
import django
|
||||
from django.conf import settings
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'procat2.settings')
|
||||
django.setup()
|
||||
|
||||
from markup.matching import find_marked_products
|
||||
|
||||
|
||||
def main(argv):
|
||||
def usage():
|
||||
print('usage: %s -s subdir [-d] file.pdf' % argv[0])
|
||||
return 100
|
||||
try:
|
||||
(opts, args) = getopt.getopt(argv[1:], 'd')
|
||||
except getopt.GetoptError:
|
||||
return usage()
|
||||
if not args: return usage()
|
||||
debug = 0
|
||||
subdir = 'test'
|
||||
for (k, v) in opts:
|
||||
if k == '-d': debug += 1
|
||||
elif k == '-s': subdir = v
|
||||
|
||||
fname = args[0]
|
||||
path = Path(fname)
|
||||
catname = path.stem
|
||||
catname = re.sub(r'[^\w]', '_', catname)
|
||||
|
||||
matches = find_marked_products(fname, subdir, catname, debug=0)
|
||||
print(matches)
|
||||
|
||||
|
||||
if __name__ == '__main__': sys.exit(main(sys.argv))
|
||||
Reference in New Issue
Block a user