diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2018-11-30 12:06:30 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2018-11-30 12:06:30 +0100 |
commit | dc8c9a24cac3725613ddd76eb4728f8f361bb48d (patch) | |
tree | 1a721522085ef59d8a9dec43df7ed66edd1ce682 | |
parent | 0c6d0acdf3b93eee221a3093ce22c0c76b0b2127 (diff) | |
download | epubgrep-0d2fccdfcd18db4859c2d5e10fb78a2bbecd1b39.tar.gz |
Add minimal setup.py and test0.2.0
-rw-r--r-- | .gitignore | 9 | ||||
-rwxr-xr-x | epubgrep.py | 34 | ||||
-rw-r--r-- | setup.py | 29 | ||||
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/test_epugrep.py | 9 |
5 files changed, 64 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61807b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.egg-info +*.pyc +*.pyo +build/ +dist/ +__pycache__/ +MANIFEST +.tox/ +.coverage diff --git a/epubgrep.py b/epubgrep.py index e3051bf..578c20b 100755 --- a/epubgrep.py +++ b/epubgrep.py @@ -8,19 +8,6 @@ from typing import Any, Dict, List, Optional, Tuple import epub_meta -parser = argparse.ArgumentParser(description='Grep through EPub book') -parser.add_argument('pattern') -parser.add_argument('filename') -parser.add_argument('-i', '--ignore-case', - action='store_true', - help="make search case insensitive") -args = parser.parse_args() - -search_flags = 0 -if args.ignore_case: - search_flags |= re.I - - def get_chapter_title(mdata:List[Dict[str, Any]], fname:str) -> Optional[Tuple[str, int]]: found_list = [(x['title'], x['index']) for x in mdata if x['src'] == fname] if len(found_list) > 0: @@ -30,7 +17,8 @@ def get_chapter_title(mdata:List[Dict[str, Any]], fname:str) -> Optional[Tuple[s return ('Unknown', 0) -def grep_book(filename:str, pattern:str, flags): +def grep_book(filename:str, pattern:str, flags:int): + assert os.path.isfile(filename), "{} is not EPub file.".format(filename) sought_RE = re.compile(pattern, flags) metadata = epub_meta.get_epub_metadata(filename) @@ -49,6 +37,18 @@ def grep_book(filename:str, pattern:str, flags): printed_title = True print(decoded_line) -assert os.path.isfile(args.filename), "{} is not EPub file.".format(args.filename) -book_fname = os.path.realpath(args.filename) -grep_book(book_fname, args.pattern, search_flags) +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Grep through EPub book') + parser.add_argument('pattern') + parser.add_argument('filename') + parser.add_argument('-i', '--ignore-case', + action='store_true', + help="make search case insensitive") + args = parser.parse_args() + + search_flags = 0 + if args.ignore_case: + search_flags |= re.I + + book_fname = os.path.realpath(args.filename) + grep_book(book_fname, args.pattern, search_flags) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6e5a25a --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +from setuptools import setup, find_packages + +setup( + name="epubgrep", + version="0.2.0", + description='Grep through EPub files', + author=u'Matěj Cepl', + author_email='mcepl@cepl.eu', + url='https://gitlab.com/mcepl/epubgrep', + packages=find_packages(), + test_suite='tests', + install_requires=['epub_meta'], + classifiers=[ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.7", + "Environment :: Console", + "Intended Audience :: Information Technology", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries :: Python Modules", + ], +) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/test_epugrep.py b/tests/test_epugrep.py new file mode 100644 index 0000000..7db430a --- /dev/null +++ b/tests/test_epugrep.py @@ -0,0 +1,9 @@ +import unittest + +import epubgrep + + +class TestEPubGrep(unittest.TestCase): + def test_epub_is_file(self): + with self.assertRaises(AssertionError): + epubgrep.grep_book('foo', 'bar', 0) |