mirror of
https://github.com/grassmunk/Chicago95.git
synced 2025-07-27 07:34:36 +02:00
Update version retrieval code
This commit is contained in:
parent
0d3cb5a6b3
commit
3e4b98d0dd
@ -31,6 +31,7 @@ import subprocess
|
|||||||
import configparser
|
import configparser
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
from decimal import *
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
@ -123,6 +124,9 @@ class ChicagoPlus:
|
|||||||
self.chicago95_theme_folder = chicago95_theme_path
|
self.chicago95_theme_folder = chicago95_theme_path
|
||||||
self.chicago95_icons_folder = chicago95_icons_path
|
self.chicago95_icons_folder = chicago95_icons_path
|
||||||
|
|
||||||
|
# Placeholder for inkscape version and path information. It will be populated with actual information after it is confirmed that the user has Inkscape
|
||||||
|
self.inkscape_info = inkscape_info("void", [0,0,0])
|
||||||
|
|
||||||
|
|
||||||
# Create the Logger
|
# Create the Logger
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
@ -166,6 +170,8 @@ class ChicagoPlus:
|
|||||||
error = True
|
error = True
|
||||||
try:
|
try:
|
||||||
inkscape_path = subprocess.check_output(["which", "inkscape"]).strip()
|
inkscape_path = subprocess.check_output(["which", "inkscape"]).strip()
|
||||||
|
#Assuming the previous portion doesn't return an exception, the placeholder information is replaced
|
||||||
|
self.get_inkscape_info()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
self.logger.critical("You need inkscape installed to use this library.")
|
self.logger.critical("You need inkscape installed to use this library.")
|
||||||
error = True
|
error = True
|
||||||
@ -2458,23 +2464,21 @@ class ChicagoPlus:
|
|||||||
|
|
||||||
def convert_to_proper_svg_with_inkscape(self, svg_out, svg_in):
|
def convert_to_proper_svg_with_inkscape(self, svg_out, svg_in):
|
||||||
self.logger.debug("{:<21} | Converting {} to {} with Inkscape".format("",svg_out, svg_in))
|
self.logger.debug("{:<21} | Converting {} to {} with Inkscape".format("",svg_out, svg_in))
|
||||||
# this is a bit of a hack to support both version of inkscape
|
|
||||||
inkscape_path = subprocess.check_output(["which", "inkscape"]).strip()
|
|
||||||
inkscape_version_cmd = subprocess.check_output([inkscape_path, "--version"])
|
|
||||||
inkscape_version = inkscape_version_cmd.splitlines()[0].split()[1].decode().split(".")[0]
|
|
||||||
|
|
||||||
if int(inkscape_version) < 1:
|
# this is a bit of a hack to support both version of inkscape
|
||||||
|
|
||||||
|
if int(self.inkscape_info.version[0]) < 1:
|
||||||
self.logger.debug("{:<21} | Using Inkscape v0.9x command".format(''))
|
self.logger.debug("{:<21} | Using Inkscape v0.9x command".format(''))
|
||||||
# Works with version 0.9x
|
# Works with version 0.9x
|
||||||
args = [
|
args = [
|
||||||
inkscape_path,
|
self.inkscape_info.path,
|
||||||
"-l", svg_out, svg_in
|
"-l", svg_out, svg_in
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
self.logger.debug("{:<21} | Using Inkscape v1.0 command".format(''))
|
self.logger.debug("{:<21} | Using Inkscape v1.0 command".format(''))
|
||||||
#works with version 1.0
|
#works with version 1.0
|
||||||
args = [
|
args = [
|
||||||
inkscape_path,
|
self.inkscape_info.path,
|
||||||
"-l", "-o", svg_out, svg_in
|
"-l", "-o", svg_out, svg_in
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2483,14 +2487,11 @@ class ChicagoPlus:
|
|||||||
|
|
||||||
def fix_with_inkscape(self, color, tmpfile):
|
def fix_with_inkscape(self, color, tmpfile):
|
||||||
self.logger.debug("{:<21} | Combining {} in {}".format("",color, tmpfile))
|
self.logger.debug("{:<21} | Combining {} in {}".format("",color, tmpfile))
|
||||||
inkscape_path = subprocess.check_output(["which", "inkscape"]).strip()
|
|
||||||
|
|
||||||
inkscape_version_cmd = subprocess.check_output([inkscape_path, "--version"])
|
|
||||||
inkscape_version = inkscape_version_cmd.splitlines()[0].split()[1].decode().split(".")[0]
|
|
||||||
|
|
||||||
if int(inkscape_version) < 1:
|
if int(self.inkscape_info.version[0]) < 1:
|
||||||
args = [
|
args = [
|
||||||
inkscape_path,
|
self.inkscape_info.path,
|
||||||
"--select="+color,
|
"--select="+color,
|
||||||
"--verb", "EditSelectSameFillColor",
|
"--verb", "EditSelectSameFillColor",
|
||||||
"--verb", "SelectionCombine",
|
"--verb", "SelectionCombine",
|
||||||
@ -2501,28 +2502,22 @@ class ChicagoPlus:
|
|||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
args = [
|
args = [
|
||||||
inkscape_path,
|
self.inkscape_info.path,
|
||||||
"-g",
|
"-g",
|
||||||
"--select="+color,
|
"--select="+color,
|
||||||
"--verb", "EditSelectSameFillColor;SelectionCombine;SelectionUnion;FileSave;FileQuit",
|
"--verb", "EditSelectSameFillColor;SelectionCombine;SelectionUnion;FileSave;FileQuit",
|
||||||
tmpfile
|
tmpfile
|
||||||
]
|
]
|
||||||
|
|
||||||
subprocess.check_call(args, stderr=subprocess.DEVNULL ,stdout=subprocess.DEVNULL)
|
subprocess.check_call(args, stderr=subprocess.DEVNULL ,stdout=subprocess.DEVNULL)\
|
||||||
|
|
||||||
|
|
||||||
def convert_to_png_with_inkscape(self, svg_in, size, png_out):
|
def convert_to_png_with_inkscape(self, svg_in, size, png_out):
|
||||||
self.logger.debug("{:<21} | Converting {} to {} of size {}".format("", svg_in, png_out, size))
|
self.logger.debug("{:<21} | Converting {} to {} of size {}".format("", svg_in, png_out, size))
|
||||||
inkscape_path = subprocess.check_output(["which", "inkscape"]).strip()
|
|
||||||
|
|
||||||
inkscape_version_cmd = subprocess.check_output([inkscape_path, "--version"])
|
|
||||||
inkscape_version = inkscape_version_cmd.splitlines()[0].split()[1].decode().split(".")[0]
|
|
||||||
|
|
||||||
size = str(size)
|
size = str(size)
|
||||||
|
|
||||||
if int(inkscape_version) < 1:
|
if int(self.inkscape_info.version[0]) < 1:
|
||||||
args = [
|
args = [
|
||||||
inkscape_path,
|
self.inkscape_info.path,
|
||||||
"--without-gui",
|
"--without-gui",
|
||||||
"-f", svg_in,
|
"-f", svg_in,
|
||||||
"--export-area-page",
|
"--export-area-page",
|
||||||
@ -2532,7 +2527,7 @@ class ChicagoPlus:
|
|||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
args = [
|
args = [
|
||||||
inkscape_path,
|
self.inkscape_info.path,
|
||||||
"--export-area-page",
|
"--export-area-page",
|
||||||
"--export-type=png",
|
"--export-type=png",
|
||||||
"-w", size,
|
"-w", size,
|
||||||
@ -2544,6 +2539,14 @@ class ChicagoPlus:
|
|||||||
|
|
||||||
subprocess.check_call(args, stderr=subprocess.DEVNULL ,stdout=subprocess.DEVNULL)
|
subprocess.check_call(args, stderr=subprocess.DEVNULL ,stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
|
def get_inkscape_info(self):
|
||||||
|
inkscape_path = subprocess.check_output(["which", "inkscape"]).strip()
|
||||||
|
|
||||||
|
inkscape_version_cmd = subprocess.check_output([inkscape_path, "--version"])
|
||||||
|
inkscape_version = inkscape_version_cmd.splitlines()[0].split()[1].decode().split(".")[0:3]
|
||||||
|
|
||||||
|
self.inkscape_info = inkscape_info(inkscape_path, inkscape_version)
|
||||||
|
|
||||||
def convert_ico_files(self, icon_filename, output_file_name):
|
def convert_ico_files(self, icon_filename, output_file_name):
|
||||||
self.logger.debug("{:<21} | Converting {} to {}".format("", icon_filename, output_file_name))
|
self.logger.debug("{:<21} | Converting {} to {}".format("", icon_filename, output_file_name))
|
||||||
convert_path = subprocess.check_output(["which", "convert"]).strip()
|
convert_path = subprocess.check_output(["which", "convert"]).strip()
|
||||||
@ -3167,6 +3170,7 @@ class ChicagoPlus:
|
|||||||
'''
|
'''
|
||||||
return logo
|
return logo
|
||||||
|
|
||||||
|
class inkscape_info:
|
||||||
|
def __init__(self, path, version):
|
||||||
|
self.path = path
|
||||||
|
self.version = version
|
Loading…
x
Reference in New Issue
Block a user