Skip to content

Commit 26ee172

Browse files
committed
qa
1 parent 7e4af34 commit 26ee172

File tree

9 files changed

+45
-29
lines changed

9 files changed

+45
-29
lines changed

documentation/reference/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A full list of `Gimpformats` project modules.
66

77
- [Gimpformats](gimpformats/index.md#gimpformats)
88
- [Binaryiotools](gimpformats/binaryiotools.md#binaryiotools)
9+
- [Enums](gimpformats/enums.md#enums)
910
- [Gimpchannel](gimpformats/GimpChannel.md#gimpchannel)
1011
- [Gimpgbrbrush](gimpformats/GimpGbrBrush.md#gimpgbrbrush)
1112
- [Gimpggrgradient](gimpformats/GimpGgrGradient.md#gimpggrgradient)

documentation/reference/gimpformats/GimpGtpToolPreset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Decode a parentheses-based file format.
195195
#### Signature
196196

197197
```python
198-
def parenFileDecode(data: bytearray) -> list[ParenFileValue]: ...
198+
def parenFileDecode(data: bytearray | bytes) -> list[ParenFileValue]: ...
199199
```
200200

201201
#### See also

documentation/reference/gimpformats/enums.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
## AllProps
2323

24-
[Show source in enums.py:205](../../../gimpformats/enums.py#L205)
24+
[Show source in enums.py:206](../../../gimpformats/enums.py#L206)
2525

2626
#### Signature
2727

@@ -33,7 +33,7 @@ class AllProps(Enum): ...
3333

3434
## ChannelProperties
3535

36-
[Show source in enums.py:173](../../../gimpformats/enums.py#L173)
36+
[Show source in enums.py:174](../../../gimpformats/enums.py#L174)
3737

3838
#### Signature
3939

@@ -45,7 +45,7 @@ class ChannelProperties(Enum): ...
4545

4646
## ColorMode
4747

48-
[Show source in enums.py:6](../../../gimpformats/enums.py#L6)
48+
[Show source in enums.py:7](../../../gimpformats/enums.py#L7)
4949

5050
#### Signature
5151

@@ -57,7 +57,7 @@ class ColorMode(Enum): ...
5757

5858
## CompositeMode
5959

60-
[Show source in enums.py:19](../../../gimpformats/enums.py#L19)
60+
[Show source in enums.py:20](../../../gimpformats/enums.py#L20)
6161

6262
#### Signature
6363

@@ -69,7 +69,7 @@ class CompositeMode(Enum): ...
6969

7070
## CompositeSpace
7171

72-
[Show source in enums.py:26](../../../gimpformats/enums.py#L26)
72+
[Show source in enums.py:27](../../../gimpformats/enums.py#L27)
7373

7474
#### Signature
7575

@@ -81,7 +81,7 @@ class CompositeSpace(Enum): ...
8181

8282
## CompressionMode
8383

84-
[Show source in enums.py:44](../../../gimpformats/enums.py#L44)
84+
[Show source in enums.py:45](../../../gimpformats/enums.py#L45)
8585

8686
#### Signature
8787

@@ -93,7 +93,7 @@ class CompressionMode(Enum): ...
9393

9494
## GeneralProperties
9595

96-
[Show source in enums.py:140](../../../gimpformats/enums.py#L140)
96+
[Show source in enums.py:141](../../../gimpformats/enums.py#L141)
9797

9898
#### Signature
9999

@@ -105,7 +105,7 @@ class GeneralProperties(Enum): ...
105105

106106
## GimpBlendMode
107107

108-
[Show source in enums.py:51](../../../gimpformats/enums.py#L51)
108+
[Show source in enums.py:52](../../../gimpformats/enums.py#L52)
109109

110110
#### Attributes
111111

@@ -140,7 +140,7 @@ class GimpBlendMode(Enum): ...
140140

141141
## ImageProperties
142142

143-
[Show source in enums.py:155](../../../gimpformats/enums.py#L155)
143+
[Show source in enums.py:156](../../../gimpformats/enums.py#L156)
144144

145145
#### Signature
146146

@@ -152,7 +152,7 @@ class ImageProperties(Enum): ...
152152

153153
## LayerProperties
154154

155-
[Show source in enums.py:184](../../../gimpformats/enums.py#L184)
155+
[Show source in enums.py:185](../../../gimpformats/enums.py#L185)
156156

157157
#### Signature
158158

@@ -164,7 +164,7 @@ class LayerProperties(Enum): ...
164164

165165
## TagColor
166166

167-
[Show source in enums.py:32](../../../gimpformats/enums.py#L32)
167+
[Show source in enums.py:33](../../../gimpformats/enums.py#L33)
168168

169169
#### Signature
170170

@@ -176,7 +176,7 @@ class TagColor(Enum): ...
176176

177177
## Units
178178

179-
[Show source in enums.py:12](../../../gimpformats/enums.py#L12)
179+
[Show source in enums.py:13](../../../gimpformats/enums.py#L13)
180180

181181
#### Signature
182182

@@ -188,7 +188,7 @@ class Units(Enum): ...
188188

189189
## merge_to
190190

191-
[Show source in enums.py:134](../../../gimpformats/enums.py#L134)
191+
[Show source in enums.py:135](../../../gimpformats/enums.py#L135)
192192

193193
#### Signature
194194

documentation/reference/gimpformats/native_convert.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## convert_xcf_to_flat_image
1111

12-
[Show source in native_convert.py:63](../../../gimpformats/native_convert.py#L63)
12+
[Show source in native_convert.py:66](../../../gimpformats/native_convert.py#L66)
1313

1414
Convert an xcf file given by `xcf_path` to some flat image (such
1515
as a jpg, png etc) given by `output_path`.
@@ -18,9 +18,12 @@ as a jpg, png etc) given by `output_path`.
1818

1919
- `xcf_path` *str* - path to a source xcf file
2020
- `output_path` *str* - path to an output file (eg a png)
21+
- `run_anyway` *bool* - force running this, unsafe!
2122

2223
#### Signature
2324

2425
```python
25-
def convert_xcf_to_flat_image(xcf_path: str, output_path: str) -> None: ...
26+
def convert_xcf_to_flat_image(
27+
xcf_path: str, output_path: str, run_anyway=False
28+
) -> None: ...
2629
```

documentation/reference/test_informal/test_gimp_document.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
77
#### Attributes
88

9-
- `encoded` - Test encoding and decoding: gimp_img.encode
10-
119
- `root_group` - Test walking through tree structure: gimp_img.walkTree()
1210

1311

gimpformats/GimpGtpToolPreset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def full_repr(self) -> str:
6666
return "".join(ret)
6767

6868

69-
def parenFileDecode(data: bytearray) -> list[ParenFileValue]:
69+
def parenFileDecode(data: bytearray | bytes) -> list[ParenFileValue]:
7070
"""Decode a parentheses-based file format.
7171
7272
(possibly "scheme" language?)

gimpformats/enums.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from aenum import Enum, extend_enum
44

55

6+
# pyright: reportGeneralTypeIssues=false
67
class ColorMode(Enum):
78
RGB = "RGB"
89
Grayscale = "Grayscale"
@@ -128,7 +129,7 @@ class GimpBlendMode(Enum):
128129

129130
# Since XCF 10 60-61
130131
SPLIT = "Split"
131-
PASS_THROUGH = "Pass through"
132+
PASS_THROUGH = "Pass through" # noqa: S105
132133

133134

134135
def merge_to(src: Enum, dest: Enum):

gimpformats/gimpXcfDocument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def insertRawLayer(self, layer: GimpLayer, index: int = -1) -> None:
377377

378378
def deleteRawLayer(self, index: int) -> None:
379379
"""Delete a layer."""
380-
self._layers.remove(index)
380+
self._layers.pop(index)
381381

382382
def walkTree(self) -> GimpGroup:
383383
root_group = GimpGroup(

gimpformats/native_convert.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
]
3232

3333

34-
def _convert_xcf_to_flat_image_windows(xcf_path: str, output_path: str) -> list[str] | None:
34+
def _convert_xcf_to_flat_image(xcf_path: str, output_path: str) -> list[str] | None:
3535
common_gimp_paths = [
3636
r"C:\Program Files\GIMP 2\bin\gimp-console-2.10.exe",
3737
r"C:\Program Files (x86)\GIMP 2\bin\gimp-console-2.10.exe",
38+
"/bin/gimp-console",
39+
"/usr/bin/gimp-console",
40+
"/usr/local/bin/gimp-console",
3841
]
3942

4043
gimp_path = None
@@ -60,30 +63,40 @@ def _convert_xcf_to_flat_image_windows(xcf_path: str, output_path: str) -> list[
6063
]
6164

6265

63-
def convert_xcf_to_flat_image(xcf_path: str, output_path: str) -> None:
66+
def convert_xcf_to_flat_image(xcf_path: str, output_path: str, *, run_anyway=False) -> None:
6467
"""Convert an xcf file given by `xcf_path` to some flat image (such
6568
as a jpg, png etc) given by `output_path`.
6669
6770
:param str xcf_path: path to a source xcf file
6871
:param str output_path: path to an output file (eg a png)
72+
:param bool run_anyway: force running this, unsafe!
6973
"""
7074
# Ensure the input .xcf path exists
7175
if not Path(xcf_path).is_file():
7276
logger.error(f"Input file does not exist: {xcf_path}")
7377
return
7478

7579
output_path = shlex.quote(output_path)
76-
if Path(output_path).suffix not in image_extensions:
77-
logger.error(f"Output file not supported: {image_extensions}")
80+
_suf = Path(output_path).suffix
81+
if _suf not in image_extensions:
82+
logger.error(f"Output file extension `{_suf}` not supported: {image_extensions}")
7883
return
7984

8085
# Check if the OS is Windows
86+
platform_supported = sys.platform in ("win32", "linux")
8187
command = None
82-
if sys.platform == "win32":
83-
command = _convert_xcf_to_flat_image_windows(xcf_path, output_path)
84-
88+
if platform_supported or (not platform_supported and run_anyway):
89+
if sys.platform in ("linux",) and _suf in (".avif", "fuck_knows"):
90+
logger.error(f"{_suf} is not supported in this system")
91+
return
92+
command = _convert_xcf_to_flat_image(xcf_path, output_path)
93+
94+
if not platform_supported and run_anyway:
95+
logger.warning(
96+
f"this script may not be supported on `{sys.platform}`, "
97+
"pass run_anyway=True to override this"
98+
)
8599
if command is None:
86-
logger.error(f"Sorry, this script is not supported on {sys.platform}")
87100
return
88101

89102
try:

0 commit comments

Comments
 (0)