Beispiel #1
0
if format not in ('svg', 'svgz'):
    print("Invalid format: "+format, file=sys.stderr)
    sys.exit(255)


#debug environment
#print(repr(os.environ))

dvisvgm = os.environ.get("KLF_USCONFIG_dvisvgm")
if not dvisvgm:
    print("Warning: dvisvgm config not set", file=sys.stderr)
    dvisvgm = "/usr/bin/dvisvgm"

print("Using dvisvgm path: {}".format(dvisvgm), file=sys.stderr)

pyklfuserscript.ensure_configured_executable(dvisvgm, exename='dvisvgm', userscript=__file__)

print("Converting file {}\n".format(dvifile), file=sys.stderr)

svgfile = re.sub(r'\.dvi$', '.svg', dvifile)

# CalledProcessError is raised if an error occurs.
output = subprocess.check_output(args=[dvisvgm, '-a', '-e', '-n', '-b', 'min', dvifile],
                                 shell=False, stderr=subprocess.STDOUT)
print("Output from {}: \n{}".format(dvisvgm, output.decode('utf-8')))

if format == 'svgz':

    gzip = ""
    if "KLF_USCONFIG_gzip" in os.environ:
        gzip = os.environ["KLF_USCONFIG_gzip"]
Beispiel #2
0
            # necessary to include /usr/bin/ etc.)
        ])
    if convert is not None:  # found
        print("convert={}".format(convert))
    sys.exit()

#
# Run script
#

format = args.format
inputfile = args.inputfile

#
# Read configuration values
#
convertexe = os.environ.get("KLF_USCONFIG_convert")
noisepixels = int(os.environ.get("KLF_USCONFIG_noisepixels",
                                 3))  # noise intensity, in pixels

pyklfuserscript.ensure_configured_executable(convertexe,
                                             exename='convert',
                                             userscript=__file__)

cmd = [
    convertexe, inputfile, '-interpolate', 'nearest', '-virtual-pixel',
    'mirror', '-spread', "{}".format(noisepixels), inputfile
]  # overwrite input file

subprocess.check_output(cmd)
Beispiel #3
0
#    has_vectorscale = True

ps_x = os.environ.get("KLF_ARG_pagesize_x")
ps_y = os.environ.get("KLF_ARG_pagesize_y")

arg_ltxengine = os.environ.get("KLF_ARG_ltxengine")

if arg_ltxengine == 'pdflatex': ltxexe = pdflatex
elif arg_ltxengine == 'xelatex': ltxexe = xelatex
elif arg_ltxengine == 'lualatex': ltxexe = lualatex
else:
    raise ValueError("Invalid latex engine: {}".format(arg_ltxengine))

print("Using engine {} at {}".format(arg_ltxengine, ltxexe), file=sys.stderr)

pyklfuserscript.ensure_configured_executable(ltxexe, exename=arg_ltxengine, userscript=__file__)


tempdir = os.path.dirname(os.environ["KLF_TEMPFNAME"])

def run_cmd(do_cmd, ignore_fail=False, callargs={}):
    print("Running " + " ".join(["'%s'"%(x) for x in do_cmd]) + "  [ in %s ]..." %(tempdir) + "\n")
    output = None
    thecallargs = {'stderr': subprocess.STDOUT}
    thecallargs.update(dict(callargs))
    try:
        output = subprocess.check_output(do_cmd, cwd=tempdir, **thecallargs)
    except subprocess.CalledProcessError as e:
        if not ignore_fail:
            print("ERROR: Exit Status "+str(e.returncode)+ "\n" + e.output)
            raise
Beispiel #4
0
pngfname = os.environ["KLF_FN_PNG"]

#

gsexe = os.environ.get("KLF_GS")

pdflatex = os.environ.get("KLF_USCONFIG_pdflatex")

dpi_value = os.environ.get("KLF_INPUT_DPI", 180)

ps_x = os.environ.get("KLF_ARG_pagesize_x")
ps_y = os.environ.get("KLF_ARG_pagesize_y")

print("Using pdflatex path: {}".format(pdflatex), file=sys.stderr)
pyklfuserscript.ensure_configured_executable(pdflatex,
                                             exename='pdflatex',
                                             userscript=__file__)

tempdir = os.path.dirname(os.environ["KLF_TEMPFNAME"])


def run_cmd(do_cmd, ignore_fail=False, callargs={}):
    print("Running " + " ".join(["'%s'" % (x) for x in do_cmd]) +
          "  [ in %s ]..." % (tempdir) + "\n")
    output = None
    thecallargs = {'stderr': subprocess.STDOUT}
    thecallargs.update(dict(callargs))
    try:
        output = subprocess.check_output(do_cmd, cwd=tempdir, **thecallargs)
    except subprocess.CalledProcessError as e:
        if not ignore_fail:

#debug environment
#print(repr(os.environ))

dvisvgm = ""
if "KLF_USCONFIG_dvisvgm" in os.environ:
    dvisvgm = os.environ["KLF_USCONFIG_dvisvgm"];

if not dvisvgm:
    print("Warning: dvisvgm config not set", file=sys.stderr)
    dvisvgm = "/usr/bin/dvisvgm";

print("Using dvisvgm path: {}".format(dvisvgm), file=sys.stderr)

pyklfuserscript.ensure_configured_executable(dvisvgm, exename='dvisvgm', userscript=__name__)

print("Converting file {}\n".format(dvifile), file=sys.stderr)

svgfile = re.sub(r'\.dvi$', '.svg', dvifile)

# CalledProcessError is raised if an error occurs.
output = subprocess.check_output(args=[dvisvgm, '-a', '-e', '-n', '-b', 'min', dvifile],
                                 shell=False, stderr=subprocess.STDOUT)
print("Output from {}: \n{}".format(dvisvgm, output.decode('utf-8')))

if format == 'svgz':

    gzip = ""
    if "KLF_USCONFIG_gzip" in os.environ:
        gzip = os.environ["KLF_USCONFIG_gzip"];
    print("Invalid format: " + format)
    sys.exit(255)

#debug environment
#print(repr(os.environ))

if "KLF_USCONFIG_inkscape" in os.environ:
    inkscape = os.environ["KLF_USCONFIG_inkscape"]
else:
    print("Warning: inkscape config not set.")
    inkscape = "inkscape"

print("Using inkscape path: {}".format(inkscape), file=sys.stderr)

pyklfuserscript.ensure_configured_executable(inkscape,
                                             exename='inkscape',
                                             userscript=__name__)

print("Converting file {}\n".format(pdffile), file=sys.stderr)

outfile = re.sub(r'\.pdf$', '.' + format, pdffile)

if format == 'svg':
    exportarg_outfile = "--export-plain-svg=" + outfile
else:
    exportarg_outfile = "--export-" + format + "=" + outfile

# CalledProcessError is raised if an error occurs.
output = subprocess.check_output(args=[inkscape, pdffile, exportarg_outfile],
                                 shell=False,
                                 stderr=subprocess.STDOUT)
if format not in FORMATS:
    print("Invalid format: "+format);
    sys.exit(255);

#debug environment
#print(repr(os.environ))

if "KLF_USCONFIG_inkscape" in os.environ:
    inkscape = os.environ["KLF_USCONFIG_inkscape"];
else:
    print("Warning: inkscape config not set.")
    inkscape = "inkscape"

print("Using inkscape path: {}".format(inkscape), file=sys.stderr)

pyklfuserscript.ensure_configured_executable(inkscape, exename='inkscape', userscript=__name__)

print("Converting file {}\n".format(pdffile), file=sys.stderr)

outfile = re.sub(r'\.pdf$', '.'+format, pdffile)

if format == 'svg':
    exportarg_outfile = "--export-plain-svg="+outfile
else:
    exportarg_outfile = "--export-"+format+"="+outfile

# CalledProcessError is raised if an error occurs.
output = subprocess.check_output(args=[
    inkscape, pdffile, exportarg_outfile
], shell=False, stderr=subprocess.STDOUT)
Beispiel #8
0
dvifname = os.environ["KLF_FN_DVI"]
pngfname = os.environ["KLF_FN_PNG"]

#

latexexe = os.environ["KLF_LATEX"]

if not latexexe:
    sys.stderr.write("Error: latex executable not found.\n")
    sys.exit(1)

dvipng = os.environ.get("KLF_USCONFIG_dvipng")

print("Using dvipng path: {}".format(dvipng), file=sys.stderr)
pyklfuserscript.ensure_configured_executable(dvipng,
                                             exename='dvipng',
                                             userscript=__file__)

tempdir = os.path.dirname(os.environ["KLF_TEMPFNAME"])


def run_cmd(do_cmd, ignore_fail=False):
    print("Running " + " ".join(["'%s'" % (x) for x in do_cmd]) +
          "  [ in %s ]..." % (tempdir) + "\n")
    res = subprocess.call(do_cmd, cwd=tempdir)
    if (not ignore_fail and res != 0):
        print("%s failed, res=%d" % (do_cmd[0], res))
        sys.exit(res >> 8)


# run latex first to get DVI