Skip to content

Commit b057903

Browse files
author
Kirill V. Lyadvinsky
committed
Moved common functions in common.py
1 parent d1b5f64 commit b057903

File tree

6 files changed

+44
-33
lines changed

6 files changed

+44
-33
lines changed

test/test_hobeta.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import unittest
1717
import tempfile
1818
from collections import namedtuple
19+
1920
from zxtools import hobeta
20-
from zxtools import safe_parse_args
21+
from zxtools.common import safe_parse_args
22+
2123
from mock import patch
2224

2325

test/test_zeus2txt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from mock import patch
2020

2121
from zxtools import zeus2txt
22-
from zxtools import safe_parse_args
22+
from zxtools.common import safe_parse_args
2323

2424

2525

zxtools/__init__.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,7 @@
77
# Licensed under the BSD 3-Clause license.
88
# See LICENSE file in the project root for full license information.
99
#
10-
"""Global constants and templates are here"""
11-
12-
import sys
13-
import logging
10+
"""Global constants"""
1411

1512
__version__ = '1.0.23'
1613
CHUNK_SIZE = 512 * 1024 # 512 KBytes
17-
18-
19-
def safe_parse_args(parser, args):
20-
"""Safely parse arguments"""
21-
try:
22-
options = parser.parse_args(args)
23-
if len(args) == 0:
24-
raise ValueError
25-
except ValueError:
26-
parser.print_help()
27-
sys.exit(0)
28-
29-
return options
30-
31-
32-
def default_main(parser):
33-
""" Default entry point implementation """
34-
args = safe_parse_args(parser, sys.argv[1:])
35-
if args.verbose:
36-
logging.basicConfig(level=logging.DEBUG)
37-
38-
if hasattr(args, 'func'):
39-
args.func(args)
40-
41-
return args

zxtools/common.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#! /usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2016 Kirill V. Lyadvinsky
5+
# http://www.codeatcpp.com
6+
# Licensed under the BSD 3-Clause license.
7+
# See LICENSE file in the project root for full license information.
8+
#
9+
""" Common functions """
10+
11+
import sys
12+
import logging
13+
14+
15+
def safe_parse_args(parser, args):
16+
"""Safely parse arguments"""
17+
try:
18+
options = parser.parse_args(args)
19+
if len(args) == 0:
20+
raise ValueError
21+
except ValueError:
22+
parser.print_help()
23+
sys.exit(0)
24+
25+
return options
26+
27+
28+
def default_main(parser):
29+
""" Default entry point implementation """
30+
args = safe_parse_args(parser, sys.argv[1:])
31+
if args.verbose:
32+
logging.basicConfig(level=logging.DEBUG)
33+
34+
if hasattr(args, 'func'):
35+
args.func(args)
36+
37+
return args

zxtools/hobeta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import argparse
1717

1818
from zxtools import CHUNK_SIZE
19-
from zxtools import default_main
19+
from zxtools.common import default_main
2020

2121
HEADER_FMT = '<8sBHHBBH'
2222
Header = namedtuple(

zxtools/zeus2txt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import io
1515

1616
from zxtools import CHUNK_SIZE
17-
from zxtools import default_main
17+
from zxtools.common import default_main
1818

1919
CODE_ALIGN_WIDTH = 35
2020

0 commit comments

Comments
 (0)