Skip to content

Commit

Permalink
Merge 5627a76 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 12, 2022
2 parents 8043790 + 5627a76 commit 22abc70
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.8.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
69 changes: 48 additions & 21 deletions img2texture/_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import os
import sys
import traceback
from enum import Enum
from pathlib import Path

Expand All @@ -9,10 +10,16 @@
from ._tiling import tile


def in_pyinstaller() -> bool:
return getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')


def print_version():
print(f'img2texture {constants.__version__} '
f'({constants.__build_timestamp__.split()[0]})\n'
f'{constants.__copyright__}')
comment = constants.__build_timestamp__.split()[0] \
if in_pyinstaller() else "pip package"
print(f'img2texture {constants.__version__} ({comment})\n'
f'{constants.__copyright__}\n'
"https://github.com/rtmigo/img2texture")


class Mode(Enum):
Expand Down Expand Up @@ -59,10 +66,13 @@ def __init__(self):
choices=[str(m.value) for m in Mode],
default=Mode.both,
help=argparse.SUPPRESS)
parser.add_argument("--trace",
action='store_true',
help=argparse.SUPPRESS)
parser.add_argument('--version',
action='store_true',
default=False,
help="Show version info and sys.exit")
help="Show version info and exit")

self._parsed = parser.parse_args()

Expand All @@ -89,6 +99,12 @@ def mode(self) -> Mode:
def tile(self) -> bool:
return self._parsed.tile

@property
def exceptions(self) -> bool:
r = self._parsed.trace
assert isinstance(r, bool)
return r


def tile_filename(texture: Path) -> Path:
basename = texture.name
Expand All @@ -100,20 +116,31 @@ def tile_filename(texture: Path) -> Path:
def cli():
args = ParsedArgs()

if args.target.exists():
if not confirm(f"File '{args.target.name}' exists. Overwrite?"):
sys.exit(3)
os.remove(args.target)

img2tex(args.source, args.target, pct=args.overlap_pct)

if args.tile:
tile_src = args.target if args.mode != Mode.none else args.source
tile_fn = tile_filename(tile_src)
if tile_fn.exists() and not confirm(
f"File '{tile_fn}' exists. Overwrite?"):
sys.exit(3)

if tile_fn.exists():
os.remove(tile_fn)
tile(tile_src, tile_fn, horizontal=2, vertical=2)
try:
if args.target.exists():
if not confirm(f"File '{args.target.name}' exists. Overwrite?"):
sys.exit(3)
os.remove(args.target)

img2tex(args.source, args.target, pct=args.overlap_pct)

if args.tile:
tile_src = args.target if args.mode != Mode.none else args.source
tile_fn = tile_filename(tile_src)
if tile_fn.exists() and not confirm(
f"File '{tile_fn}' exists. Overwrite?"):
sys.exit(3)

if tile_fn.exists():
os.remove(tile_fn)
tile(tile_src, tile_fn, horizontal=2, vertical=2)

except Exception as e:
if isinstance(e, SystemExit):
raise
if args.exceptions:
print(traceback.format_exc())
else:
print(f"ERROR: {e}")
print("Run with --trace to see full exception info.")
sys.exit(1)
6 changes: 3 additions & 3 deletions img2texture/_constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__version__ = "1.0.2"
__version__ = "1.0.5"

__copyright__ = "(c) Artsiom iG (rtmigo.github.io)"
__copyright__ = "(c) Artsiom iG <ortemeo@gmail.com>"
__license__ = "MIT"
__build_timestamp__ = "2022-10-12 01:21:53"
__build_timestamp__ = "2022-10-12 05:30:19"

0 comments on commit 22abc70

Please sign in to comment.