Skip to content

Commit

Permalink
!!pypi !!master !!release
Browse files Browse the repository at this point in the history
  • Loading branch information
rtmigo committed Oct 12, 2022
1 parent 85f692f commit 145b7ef
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 26 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
65 changes: 43 additions & 22 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,16 +10,16 @@
from ._tiling import tile


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


def print_version():
comment = constants.__build_timestamp__.split()[0] \
if is_is_pyinstaller() else "pip package"
print(f'img2texture {constants.__version__}'
f' ({comment})\n'
f'{constants.__copyright__}')
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 @@ -65,6 +66,9 @@ 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,
Expand Down Expand Up @@ -95,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 @@ -106,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 05:16:50"
__build_timestamp__ = "2022-10-12 05:30:19"

0 comments on commit 145b7ef

Please sign in to comment.