pyscape 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- escapy/__init__.py +18 -0
- escapy/__main__.py +178 -0
- escapy/commons.py +608 -0
- escapy/config_parser.py +284 -0
- escapy/data/escapy.conf +139 -0
- escapy/encodings/__init__.py +0 -0
- escapy/encodings/abicomp.py +197 -0
- escapy/encodings/brascii.py +36 -0
- escapy/encodings/cp774.py +63 -0
- escapy/encodings/i18n_codecs.py +127 -0
- escapy/encodings/iscii.py +227 -0
- escapy/encodings/mazovia.py +56 -0
- escapy/encodings/ram_codec.py +107 -0
- escapy/fonts.py +243 -0
- escapy/grammar.py +663 -0
- escapy/parser.py +4208 -0
- escapy/user_defined_characters.py +308 -0
- pyscape-1.0.0.dist-info/LICENSE +661 -0
- pyscape-1.0.0.dist-info/METADATA +704 -0
- pyscape-1.0.0.dist-info/RECORD +23 -0
- pyscape-1.0.0.dist-info/WHEEL +5 -0
- pyscape-1.0.0.dist-info/entry_points.txt +2 -0
- pyscape-1.0.0.dist-info/top_level.txt +1 -0
escapy/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# EscaPy is a software allowing to convert EPSON ESC/P, ESC/P2
|
|
2
|
+
# printer control language files into PDF files.
|
|
3
|
+
# Copyright (C) 2024-2025 Ysard
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Affero General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
"""Public package variables used for the release process"""
|
|
18
|
+
__version__ = "1.0.0"
|
escapy/__main__.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# EscaPy is a software allowing to convert EPSON ESC/P, ESC/P2
|
|
2
|
+
# printer control language files into PDF files.
|
|
3
|
+
# Copyright (C) 2024-2025 Ysard
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Affero General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
"""EscaPy entry point"""
|
|
18
|
+
|
|
19
|
+
# Standard imports
|
|
20
|
+
import argparse
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
import sys
|
|
23
|
+
import shutil
|
|
24
|
+
|
|
25
|
+
# Custom imports
|
|
26
|
+
from escapy import __version__
|
|
27
|
+
from escapy.config_parser import load_config, build_parser_params
|
|
28
|
+
from escapy.fonts import setup_fonts
|
|
29
|
+
from escapy.parser import ESCParser
|
|
30
|
+
import escapy.commons as cm
|
|
31
|
+
from escapy.commons import CONFIG_FILES, USER_CONFIG_FILE, EMBEDDED_CONFIG_FILE
|
|
32
|
+
|
|
33
|
+
LOGGER = cm.logger()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def choose_config_file(config_file: [Path | None]) -> Path:
|
|
37
|
+
"""Get an existing configuration file
|
|
38
|
+
|
|
39
|
+
Search the config file in the current directory, then in `~/.local/share/escapy`.
|
|
40
|
+
If none has been found: create a config file from the embedded one, in the
|
|
41
|
+
user configuration folder and use it.
|
|
42
|
+
The filename is defined in :meth:`escapy.commons.CONFIG_FILE`.
|
|
43
|
+
|
|
44
|
+
:param config_file: Configuration file path from the cli. Can be None if the
|
|
45
|
+
argument is not used.
|
|
46
|
+
:return: A Path for a valid configuration file, ready to be loaded in the
|
|
47
|
+
ConfigParser.
|
|
48
|
+
"""
|
|
49
|
+
if isinstance(config_file, Path):
|
|
50
|
+
# Config file from command line
|
|
51
|
+
if not config_file.exists():
|
|
52
|
+
LOGGER.critical("Configuration file <%s> not found!", config_file)
|
|
53
|
+
raise SystemExit
|
|
54
|
+
return config_file
|
|
55
|
+
|
|
56
|
+
# Search the config file in the current directory, then in ~/.local/share/
|
|
57
|
+
g = [path for path in CONFIG_FILES if path.exists()]
|
|
58
|
+
if not g:
|
|
59
|
+
# If none has been found: create the config file from the embedded one
|
|
60
|
+
# LOGGER.debug("Initialize new default config at <%s>", USER_CONFIG_FILE)
|
|
61
|
+
USER_CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
shutil.copy(EMBEDDED_CONFIG_FILE, USER_CONFIG_FILE)
|
|
63
|
+
return USER_CONFIG_FILE
|
|
64
|
+
|
|
65
|
+
# Use the first file found
|
|
66
|
+
config_file = g[0]
|
|
67
|
+
# LOGGER.debug("Use config at <%s>", config_file)
|
|
68
|
+
return config_file
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def escapy_entry_point(**kwargs):
|
|
72
|
+
"""The main routine."""
|
|
73
|
+
# Open input file
|
|
74
|
+
esc_prn_file_content = kwargs["esc_prn"].buffer.read()
|
|
75
|
+
if not esc_prn_file_content:
|
|
76
|
+
LOGGER.critical("Input file is empty!")
|
|
77
|
+
raise SystemExit
|
|
78
|
+
|
|
79
|
+
# Parse the config file and preload fonts search routines
|
|
80
|
+
config = load_config(config_file=kwargs["config"])
|
|
81
|
+
configured_fonts = setup_fonts(config)
|
|
82
|
+
|
|
83
|
+
params = build_parser_params(config)
|
|
84
|
+
params.update(kwargs)
|
|
85
|
+
|
|
86
|
+
LOGGER.info("EscaPy start; %s", __version__)
|
|
87
|
+
ESCParser(
|
|
88
|
+
esc_prn_file_content,
|
|
89
|
+
available_fonts=configured_fonts,
|
|
90
|
+
output_file=kwargs["output"],
|
|
91
|
+
**params,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def args_to_params(args): # pragma: no cover
|
|
96
|
+
"""Return argparse namespace as a dict {variable name: value}"""
|
|
97
|
+
return dict(vars(args).items())
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def main(): # pragma: no cover
|
|
101
|
+
"""Entry point and argument parser"""
|
|
102
|
+
|
|
103
|
+
def get_formatter_class(prog):
|
|
104
|
+
"""Limit help width"""
|
|
105
|
+
return argparse.ArgumentDefaultsHelpFormatter(
|
|
106
|
+
prog, max_help_position=25, width=90
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
parser = argparse.ArgumentParser(prog="", formatter_class=get_formatter_class)
|
|
110
|
+
|
|
111
|
+
parser.add_argument(
|
|
112
|
+
"esc_prn",
|
|
113
|
+
help="ESC raw printer file. - to read from stdin.",
|
|
114
|
+
type=argparse.FileType("r"),
|
|
115
|
+
default=sys.stdin,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
parser.add_argument(
|
|
119
|
+
"--pins",
|
|
120
|
+
nargs="?",
|
|
121
|
+
help="number of needles of the print head (9, 24, 48). "
|
|
122
|
+
"Leave it unset for ESCP2 modern printers. (default: unset)",
|
|
123
|
+
default=argparse.SUPPRESS, # Absent by default (handled later)
|
|
124
|
+
type=int,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
parser.add_argument(
|
|
128
|
+
"--single_sheets",
|
|
129
|
+
help="single-sheets or continuous paper. (default: single-sheets)",
|
|
130
|
+
default=argparse.SUPPRESS, # Absent by default (handled later)
|
|
131
|
+
action=argparse.BooleanOptionalAction,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
parser.add_argument(
|
|
135
|
+
"-o",
|
|
136
|
+
"--output",
|
|
137
|
+
help="PDF output file. - to write on stdout.",
|
|
138
|
+
type=argparse.FileType("w"),
|
|
139
|
+
nargs="?",
|
|
140
|
+
default="output.pdf",
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
parser.add_argument(
|
|
144
|
+
"-c",
|
|
145
|
+
"--config",
|
|
146
|
+
nargs="?",
|
|
147
|
+
help="configuration file to use. "
|
|
148
|
+
"(default: ./escapy.conf, ~/.local/share/escapy/escapy.conf)",
|
|
149
|
+
default=argparse.SUPPRESS, # Absent by default (handled later)
|
|
150
|
+
type=Path,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
parser.add_argument(
|
|
154
|
+
"-db",
|
|
155
|
+
"--userdef_db_filepath",
|
|
156
|
+
nargs="?",
|
|
157
|
+
help="mappings between user-defined chararacter codes and unicode. "
|
|
158
|
+
"(default: ./user_defined_mapping.json)",
|
|
159
|
+
default=argparse.SUPPRESS, # Absent by default (handled later)
|
|
160
|
+
type=Path,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
parser.add_argument("-v", "--version", action="version", version=__version__)
|
|
164
|
+
|
|
165
|
+
# Get program args and launch associated command
|
|
166
|
+
args = parser.parse_args()
|
|
167
|
+
|
|
168
|
+
params = args_to_params(args)
|
|
169
|
+
|
|
170
|
+
# Handle configuration file
|
|
171
|
+
params["config"] = choose_config_file(params.get("config"))
|
|
172
|
+
|
|
173
|
+
# Do magic
|
|
174
|
+
escapy_entry_point(**params)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
if __name__ == "__main__": # pragma: no cover
|
|
178
|
+
main()
|