Optionsschalter vereinheitlicht, .sh-Skripte von überall aufrufbar
- gleiche Aufgabe = gleicher Schalter in allen Programmen: -c/--config (Alias --cfg), -i, -o/--outdir, --section, --format, -f/--force, -j, -t/--test, -y/--dry, -v - svgconvert: -o statt -s (Alias --svgfolder), --section statt --format für die Sektion (Standard png), --format überschreibt das Bildformat - webscan: --timeout und --browser nur noch lang (kollidierten mit -t/-b) - glyphextract: -i nimmt Glyph oder Font, -e extrahiert (statt -f/-t) - setenv.sh ermittelt das Projektverzeichnis selbst, alle .sh laden es relativ zum Skript; extract-font/fonttest reichen weitere Optionen durch - Hilfetexte korrigiert, doc/README.md: Abschnitt "Gemeinsame Optionen" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
28f2bcdb32
commit
6bdaa62a7d
+19
-22
@@ -178,26 +178,26 @@ def main():
|
||||
print('"' + out_dir + '" does not exist. Please give the directory for the output!')
|
||||
return 1
|
||||
|
||||
if options.infile:
|
||||
if os.path.isfile(options.infile):
|
||||
# ein Buchstabe (extract-glyph.sh)
|
||||
if not os.path.isfile(options.infile) or not os.path.getsize(options.infile):
|
||||
print('input file does not exist')
|
||||
if not os.path.getsize(options.infile):
|
||||
print('input file is empty')
|
||||
return 1
|
||||
base, config = write_glyph(options.infile, out_dir, options.extract)
|
||||
with open(os.path.join(out_dir, base + '.cfg'), 'w', encoding='utf-8', newline='\n') as fh:
|
||||
fh.write(config)
|
||||
return 0
|
||||
|
||||
name = options.font or options.test
|
||||
source = font_source(name)
|
||||
# alle Buchstaben eines Fonts
|
||||
source = font_source(options.infile)
|
||||
configs = []
|
||||
for svg_path in sorted_glyphs(source):
|
||||
base, config = write_glyph(svg_path, out_dir, extract=bool(options.font))
|
||||
base, config = write_glyph(svg_path, out_dir, options.extract)
|
||||
print(base)
|
||||
configs.append((base, config))
|
||||
|
||||
if options.font:
|
||||
# ein Font (extract-font.sh): alle Sektionen in <font>.cfg
|
||||
if options.extract:
|
||||
# Font (extract-font.sh): alle Sektionen in <font>.cfg
|
||||
cfg_name = os.path.basename(os.path.normpath(source)) + '.cfg'
|
||||
with open(os.path.join(out_dir, cfg_name), 'w', encoding='utf-8', newline='\n') as fh:
|
||||
fh.write(''.join(config for _, config in configs))
|
||||
@@ -211,36 +211,33 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = optparse.OptionParser(usage="""%prog [options]
|
||||
parser = optparse.OptionParser(usage="""%prog -i <glyph.svg | font> [-e] [options]
|
||||
|
||||
Example usage
|
||||
-------------
|
||||
|
||||
one glyph, to test it later with inkscape:
|
||||
one glyph, test picture to check it with inkscape:
|
||||
$ %prog -i ../in/ausgangsschrift/a.svg
|
||||
one glyph, extract the points and text for the font:
|
||||
$ %prog -i ../in/ausgangsschrift/a.svg -e
|
||||
all glyphs of a font (directory in in/) including the font config:
|
||||
$ %prog -f ausgangsschrift
|
||||
all glyphs of a font (directory in in/ or a path) including the font config:
|
||||
$ %prog -i ausgangsschrift -e
|
||||
test pictures of all glyphs of a font:
|
||||
$ %prog -t ausgangsschrift
|
||||
$ %prog -i ausgangsschrift
|
||||
""", version='%prog ' + __version__)
|
||||
|
||||
parser.add_option("-i", "--infile", dest="infile",
|
||||
help="svg file of one glyph")
|
||||
help="svg file of one glyph or directory with the glyphs of a font")
|
||||
parser.add_option("-e", "--extract", dest="extract", action='store_true', default=False,
|
||||
help="with -i: extract the glyph for the font instead of a test picture")
|
||||
parser.add_option("-f", "--font", dest="font",
|
||||
help="directory with the glyphs of a font: create glyphs and font config")
|
||||
parser.add_option("-t", "--test", dest="test",
|
||||
help="directory with the glyphs of a font: create test pictures")
|
||||
help="extract the glyphs for the font (and write <font>.cfg) "
|
||||
"instead of test pictures")
|
||||
parser.add_option("-o", "--outdir", dest="outdir",
|
||||
default=os.environ.get('PICCREATE_OUT', '.'),
|
||||
help="directory for the output. default is $PICCREATE_OUT")
|
||||
help="directory where the files will be written. default is $PICCREATE_OUT")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
if sum(1 for o in (options.infile, options.font, options.test) if o) != 1:
|
||||
parser.error('please give exactly one of -i, -f or -t')
|
||||
if not options.infile:
|
||||
parser.error('please give a glyph or a font with -i')
|
||||
sys.exit(main())
|
||||
|
||||
# vim: set tw=80 ft=python ts=4 sw=4:
|
||||
|
||||
+5
-5
@@ -370,20 +370,20 @@ Read Confg, create wakeup and scale this kind of jiffy box
|
||||
|
||||
""", version='%prog ' + __version__)
|
||||
|
||||
parser.add_option("-c", "--cfg", dest="config", default="test",
|
||||
help="name of the config file with the Name of the rows to be used.",
|
||||
parser.add_option("-c", "--config", "--cfg", dest="config", default="test",
|
||||
help="name of the config file in cfg/ with the lines to be written",
|
||||
metavar="CONFIG_FILE")
|
||||
parser.add_option("-i", "--infile", dest="infile",
|
||||
help="csv file with input of names/content",
|
||||
action='store')
|
||||
parser.add_option("-s", "--startfrom", dest="startfrom",
|
||||
help="csv file with input of names/content",
|
||||
help="start the numbering again at every word / capital letter",
|
||||
action='store_true')
|
||||
parser.add_option("-o", "--outdir", dest="outdir", default=os.path.expandvars('$PICCREATE_OUT'),
|
||||
help="path to the directory where the maps will be generated",
|
||||
help="directory where the pictures will be written. default is $PICCREATE_OUT",
|
||||
action='store')
|
||||
parser.add_option("-y", "--dry", dest="dry",
|
||||
help="dont generate images. Just ask the coordinates and fill database.", action='store_true' )
|
||||
help="dont write files, print the svg instead", action='store_true' )
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
|
||||
+21
-14
@@ -123,16 +123,14 @@ def main():
|
||||
print('ImageMagick not found. Please install it (https://imagemagick.org).')
|
||||
return None
|
||||
#set the workpath and the default config
|
||||
work_path = os.path.expandvars('$PICCREATE_OUT')
|
||||
if options.svgfolder:
|
||||
work_path = os.path.expandvars(options.svgfolder)
|
||||
work_path = os.path.expandvars(options.outdir)
|
||||
if not os.path.exists(work_path):
|
||||
print('\"'+ work_path +'\" does not exist. Please give the name of the folder with the svg-files!')
|
||||
return None
|
||||
pic_config = {
|
||||
'width' : '600',
|
||||
'height' : '200',
|
||||
'format' : options.format,
|
||||
'format' : options.format or 'jpg',
|
||||
'density' : '150',
|
||||
'background' : 'white',
|
||||
'folder' : work_path,
|
||||
@@ -162,7 +160,12 @@ def main():
|
||||
config = configparser.RawConfigParser()
|
||||
config.read(config_path, encoding='utf-8')
|
||||
# fill the config
|
||||
pic_config = dict(config.items(options.format))
|
||||
if not config.has_section(options.section):
|
||||
print('section [' + options.section + '] is missing in ' + config_path)
|
||||
return None
|
||||
pic_config = dict(config.items(options.section))
|
||||
if options.format:
|
||||
pic_config['format'] = options.format
|
||||
if options.background:
|
||||
pic_config['background'] = options.background
|
||||
elif 'background' in pic_config:
|
||||
@@ -221,14 +224,17 @@ Read Confg, create wakeup and scale this kind of jiffy box
|
||||
parser.add_option("-b", "--background", dest="background",
|
||||
help="set the backgroundcolor. 'none' for transparent",
|
||||
action='store')
|
||||
parser.add_option("-c", "--config", dest="config",
|
||||
help="config file with all data for jobs",
|
||||
parser.add_option("-c", "--config", "--cfg", dest="config",
|
||||
help="config file in cfg/ with the picture sizes",
|
||||
action='store')
|
||||
parser.add_option("-f", "--force", dest="force", default=False,
|
||||
help="create the pictures, no matter if they alreads exist",
|
||||
help="create the pictures, no matter if they already exist",
|
||||
action='store_true')
|
||||
parser.add_option("--format", dest="format", default='jpg',
|
||||
help="format of the picture",
|
||||
parser.add_option("--section", dest="section", default='png',
|
||||
help="section in the config file. default is png",
|
||||
action='store')
|
||||
parser.add_option("--format", dest="format",
|
||||
help="jpg or png, overrides the config",
|
||||
action='store')
|
||||
parser.add_option("-i", "--infile", dest="infile",
|
||||
help="csv file with input of names/content",
|
||||
@@ -239,8 +245,10 @@ Read Confg, create wakeup and scale this kind of jiffy box
|
||||
parser.add_option("-p", "--progress", dest="progress",
|
||||
help="print a progression bar",
|
||||
action='store_true')
|
||||
parser.add_option("-s", "--svgfolder", dest="svgfolder",
|
||||
help="path to the folder with the svg-files",
|
||||
parser.add_option("-o", "--outdir", "--svgfolder", dest="outdir",
|
||||
default=os.path.expandvars('$PICCREATE_OUT'),
|
||||
help="folder with the svg files, the pictures are written there too. "
|
||||
"default is $PICCREATE_OUT",
|
||||
action='store')
|
||||
parser.add_option("-t", "--test", dest="test",
|
||||
help="number of default svg-files that will be created and tested",
|
||||
@@ -249,8 +257,7 @@ Read Confg, create wakeup and scale this kind of jiffy box
|
||||
help="print the status of the conversion",
|
||||
action='store_true')
|
||||
parser.add_option("-y", "--dry", dest="dry",
|
||||
help="dont generate images. \
|
||||
just try if the conversion would success",
|
||||
help="dont generate images, just try if the conversion would succeed",
|
||||
action='store_true')
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
+3
-3
@@ -235,7 +235,7 @@ Screenshots of all urls in in/kunden.csv (lines: customerid;url):
|
||||
$ %prog -c webscan -i kunden
|
||||
""", version='%prog ' + __version__)
|
||||
|
||||
parser.add_option("-c", "--cfg", dest="config", default="webscan",
|
||||
parser.add_option("-c", "--config", "--cfg", dest="config", default="webscan",
|
||||
help="config file with a [webscan] section (width, height, format)",
|
||||
metavar="CONFIG_FILE")
|
||||
parser.add_option("--section", dest="section", default="webscan",
|
||||
@@ -248,11 +248,11 @@ Screenshots of all urls in in/kunden.csv (lines: customerid;url):
|
||||
help="jpg or png, overrides the config")
|
||||
parser.add_option("-j", "--jobs", dest="jobs", default=4,
|
||||
help="number of pages loaded in parallel. default is 4")
|
||||
parser.add_option("-t", "--timeout", dest="timeout", default=20,
|
||||
parser.add_option("--timeout", dest="timeout", default=20,
|
||||
help="seconds to wait for a page. default is 20")
|
||||
parser.add_option("-f", "--force", dest="force", action='store_true',
|
||||
help="create the pictures, no matter if they already exist")
|
||||
parser.add_option("-b", "--browser", dest="browser",
|
||||
parser.add_option("--browser", dest="browser",
|
||||
default=os.environ.get('PICCREATE_BROWSER'),
|
||||
help="path to a chromium executable instead of the playwright one "
|
||||
"(default: $PICCREATE_BROWSER)")
|
||||
|
||||
Reference in New Issue
Block a user