From c830c1e70efe43c5dec4d56ea7c0fdb4cbf2e50e Mon Sep 17 00:00:00 2001 From: Alberto Pettarin Date: Sun, 19 Oct 2014 22:19:51 +0200 Subject: [PATCH] Support for bash/zsh autocompletion via argcomplete --- OUTPUT.md | 56 +++++++++++++++++++++--------------------- README.md | 65 +++++++++++++++++++++++++++---------------------- src/genEPUB.py | 0 src/glyphIgo.py | 25 ++++++++++++++----- 4 files changed, 83 insertions(+), 63 deletions(-) mode change 100644 => 100755 src/genEPUB.py mode change 100644 => 100755 src/glyphIgo.py diff --git a/OUTPUT.md b/OUTPUT.md index e274fa8..8e16ea4 100644 --- a/OUTPUT.md +++ b/OUTPUT.md @@ -3,7 +3,7 @@ ## Print the list of glyphs in `font.ttf` ``` -$ python glyphIgo.py list -f font.ttf +$ ./glyphIgo.py list -f font.ttf [INFO] Glyphs in 'font.ttf': ' ' 32 0x20 SPACE @@ -226,7 +226,7 @@ $ python glyphIgo.py list -f font.ttf ## Print the list of characters in `ebook.epub` ``` -$ python glyphIgo.py list -e ebook.epub +$ ./glyphIgo.py list -e ebook.epub [INFO] Characters in 'ebook.epub': '\t' 9 0x9 UNKNOWN NAME 3 @@ -334,7 +334,7 @@ $ python glyphIgo.py list -e ebook.epub ## As in the previous example, but sort characters by count ``` -$ python glyphIgo.py list -e ebook.epub -s +$ ./glyphIgo.py list -e ebook.epub -s [INFO] Characters in 'ebook.epub': ' ' 32 0x20 SPACE 220917 @@ -442,7 +442,7 @@ $ python glyphIgo.py list -e ebook.epub -s ## As in the previous example, but also generate an EPUB file (`test_ebook.epub`) containing the list of Unicode characters in `ebook.epub` ``` -$ python glyphIgo.py list -e ebook.epub -s -u -o test_ebook.epub +$ ./glyphIgo.py list -e ebook.epub -s -u -o test_ebook.epub [INFO] Characters in 'ebook.epub': ' ' 32 0x20 SPACE 220917 @@ -551,7 +551,7 @@ $ python glyphIgo.py list -e ebook.epub -s -u -o test_ebook.epub ## Check whether all the characters in `ebook.epub` can be displayed by `font.otf` ``` -$ python glyphIgo.py check -f font.otf -e ebook.epub +$ ./glyphIgo.py check -f font.otf -e ebook.epub [INFO] Font 'font.otf' contains all the glyphs for displaying ebook 'ebook.epub' ``` @@ -561,7 +561,7 @@ $ python glyphIgo.py check -f font.otf -e ebook.epub ## Check whether all the characters in `ebook2.epub` can be displayed by `font.ttf` ``` -$ python glyphIgo.py check -f font.ttf -e ebook2.epub +$ ./glyphIgo.py check -f font.ttf -e ebook2.epub [INFO] Font 'font.ttf' misses the following glyphs for displaying ebook 'ebook2.epub': 'Ā' 256 0x100 LATIN CAPITAL LETTER A WITH MACRON 42 @@ -594,7 +594,7 @@ $ python glyphIgo.py check -f font.ttf -e ebook2.epub ## As in the previous example, but sort missing characters (if any) by their count (in `ebook2.epub`) instead of by Unicode codepoint ``` -$ python glyphIgo.py check -f font.ttf -e ebook2.epub -s +$ ./glyphIgo.py check -f font.ttf -e ebook2.epub -s [INFO] Font 'font.ttf' misses the following glyphs for displaying ebook 'ebook2.epub': 'ā' 257 0x101 LATIN SMALL LETTER A WITH MACRON 2510 @@ -627,7 +627,7 @@ $ python glyphIgo.py check -f font.ttf -e ebook2.epub -s ## As in the previous example, but also generate an EPUB files listing the missing characters (`missing.epub`) ``` -$ python glyphIgo.py check -f font.ttf -e ebook2.epub -s -u -o missing.epub +$ ./glyphIgo.py check -f font.ttf -e ebook2.epub -s -u -o missing.epub [INFO] Font 'font.ttf' misses the following glyphs for displaying ebook 'ebook2.epub': 'ā' 257 0x101 LATIN SMALL LETTER A WITH MACRON 2510 @@ -661,7 +661,7 @@ $ python glyphIgo.py check -f font.ttf -e ebook2.epub -s -u -o missing.epub ## Subset `font.otf` into `minimized.otf` by copying only the glyphs that appear in `ebook.epub` ``` -$ python glyphIgo.py subset -f font.otf -e ebook.epub -o minimized.otf +$ ./glyphIgo.py subset -f font.otf -e ebook.epub -o minimized.otf [INFO] Subsetting font 'font.otf' with ebook 'ebook.epub' into new font 'minimized.otf', containing the following glyphs: ' ' 32 0x20 SPACE @@ -768,7 +768,7 @@ $ python glyphIgo.py subset -f font.otf -e ebook.epub -o minimized.otf ## Convert `font.ttf` (TTF) into `new.font.otf` (OTF) ``` -$ python glyphIgo.py convert -f font.ttf -o new.font.otf +$ ./glyphIgo.py convert -f font.ttf -o new.font.otf [INFO] Converted font 'font.ttf' into font 'new.font.otf'. ``` @@ -778,7 +778,7 @@ $ python glyphIgo.py convert -f font.ttf -o new.font.otf ## Print the list of characters in `page.xhtml`, sorted by their count ``` -$ python glyphIgo.py list -p page.xhtml -s +$ ./glyphIgo.py list -p page.xhtml -s [INFO] Characters in 'page.xhtml': ' ' 32 0x20 SPACE 224 @@ -869,7 +869,7 @@ $ python glyphIgo.py list -p page.xhtml -s ## As in the previous example, but preserve X(HT)ML tags instead of stripping them away ``` -$ python glyphIgo.py list -p page.xhtml -s --preserve +$ ./glyphIgo.py list -p page.xhtml -s --preserve [INFO] Characters in 'page.xhtml': ' ' 32 0x20 SPACE 530 @@ -967,7 +967,7 @@ $ python glyphIgo.py list -p page.xhtml -s --preserve ## Count the number of characters in `ebook.epub` ``` -$ python glyphIgo.py count -e ebook.epub +$ ./glyphIgo.py count -e ebook.epub [INFO] Number of characters in 'ebook.epub': 1310570 @@ -978,7 +978,7 @@ $ python glyphIgo.py count -e ebook.epub ## Lookup for Unicode character `INTERROBANG` ``` -$ python glyphIgo.py lookup -c "INTERROBANG" +$ ./glyphIgo.py lookup -c "INTERROBANG" [INFO] Matches found for 'INTERROBANG': Name INTERROBANG @@ -1000,7 +1000,7 @@ NFD ‽ ## Heuristic lookup for Unicode character `INTERROBANG` ``` -$ python glyphIgo.py lookup -c "INTERROBANG" --heuristic +$ ./glyphIgo.py lookup -c "INTERROBANG" --heuristic [INFO] Matches found for 'INTERROBANG': Name INTERROBANG @@ -1034,7 +1034,7 @@ NFD ⸘ ## Lookup for Unicode character `LATIN CAPITAL LETTER A WITH MACRON` ``` -$ python glyphIgo.py lookup -c "LATIN CAPITAL LETTER A WITH MACRON" +$ ./glyphIgo.py lookup -c "LATIN CAPITAL LETTER A WITH MACRON" [INFO] Matches found for 'LATIN CAPITAL LETTER A WITH MACRON': Name LATIN CAPITAL LETTER A WITH MACRON @@ -1056,7 +1056,7 @@ NFD Ā ## Lookup for Unicode character `a` ``` -$ python glyphIgo.py lookup -c a +$ ./glyphIgo.py lookup -c a [INFO] Matches found for 'a': Name LATIN SMALL LETTER A @@ -1078,7 +1078,7 @@ NFD a ## Lookup for Unicode character whose codepoint is 97 (decimal) ``` -$ python glyphIgo.py lookup -c 97 +$ ./glyphIgo.py lookup -c 97 [INFO] Matches found for '97': Name LATIN SMALL LETTER A @@ -1100,7 +1100,7 @@ NFD a ## Lookup for Unicode character whose codepoint is 61 (hexadecimal) ``` -$ python glyphIgo.py lookup -c 0x61 +$ ./glyphIgo.py lookup -c 0x61 [INFO] Matches found for '0x61': Name LATIN SMALL LETTER A @@ -1123,7 +1123,7 @@ NFD a ## Heuristic lookup for Greek omega letters with oxia ``` -$ python glyphIgo.py lookup -c "GREEK OMEGA OXIA" --heuristic +$ ./glyphIgo.py lookup -c "GREEK OMEGA OXIA" --heuristic [INFO] Matches found for 'GREEK OMEGA OXIA': Name GREEK SMALL LETTER OMEGA WITH PSILI AND OXIA @@ -1265,7 +1265,7 @@ NFD Ώ ## Lookup Unicode character `RAIN` and print compact output ``` -$ python glyphIgo.py lookup -c "RAIN" --compact +$ ./glyphIgo.py lookup -c "RAIN" --compact [INFO] Matches found for 'RAIN': ⛆ RAIN (U+26C6) @@ -1276,7 +1276,7 @@ $ python glyphIgo.py lookup -c "RAIN" --compact ## Lookup Unicode characters whose names contain `RAIN` and print compact output ``` -$ python glyphIgo.py lookup -c "RAIN" --compact --heuristic +$ ./glyphIgo.py lookup -c "RAIN" --compact --heuristic [INFO] Matches found for 'RAIN': ☔ UMBRELLA WITH RAIN DROPS (U+2614) @@ -1291,7 +1291,7 @@ $ python glyphIgo.py lookup -c "RAIN" --compact --heuristic ## (De)obfuscate font `font.otf` with the given ID into `obf.font.otf`, using the IDPF algorithm ``` -$ python glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf +$ ./glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf [INFO] (De)obfuscated font 'font.otf' into 'obf.font.otf' using id 'urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd' and IDPF algorithm. ``` @@ -1301,7 +1301,7 @@ $ python glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3- ## As above, but use Adobe algorithm ``` -$ python glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf --adobe +$ ./glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf --adobe [INFO] (De)obfuscated font 'font.otf' into 'obf.font.otf' using id 'urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd' and Adobe algorithm. ``` @@ -1311,7 +1311,7 @@ $ python glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3- ## List the range and name of all Unicode blocks ``` -$ python glyphIgo.py list --blocks +$ ./glyphIgo.py list --blocks [INFO] Unicode Blocks [INFO] Range Start Stop Start Stop Name @@ -1574,7 +1574,7 @@ $ python glyphIgo.py list --blocks ## List the characters in the Cyrillic range ``` -$ python glyphIgo.py list -r "Cyrillic" +$ ./glyphIgo.py list -r "Cyrillic" [INFO] Characters in range 'Cyrillic': 'Ѐ' 1024 0x400 CYRILLIC CAPITAL LETTER IE WITH GRAVE 1 @@ -1839,7 +1839,7 @@ $ python glyphIgo.py list -r "Cyrillic" ## List the characters in the 0x120-0x127 (hexadecimal) range ``` -$ python glyphIgo.py list -r 0x120-0x127 +$ ./glyphIgo.py list -r 0x120-0x127 [INFO] Characters in range '0x120-0x127': 'Ġ' 288 0x120 LATIN CAPITAL LETTER G WITH DOT ABOVE 1 @@ -1857,7 +1857,7 @@ $ python glyphIgo.py list -r 0x120-0x127 ## List the characters in the 120-127 (decimal) range ``` -$ python glyphIgo.py list -r 120-127 +$ ./glyphIgo.py list -r 120-127 [INFO] Characters in range '120-127': 'x' 120 0x78 LATIN SMALL LETTER X 1 diff --git a/README.md b/README.md index 3035459..dcf2fc2 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ as an EPUB file for quick testing on an eReader. ## Usage ``` -$ python glyphIgo.py check|convert|count|list|lookup|obfuscate|subset [options] +$ ./glyphIgo.py check|convert|count|list|lookup|obfuscate|subset [options] optional arguments: -h, --help show this help message and exit @@ -82,74 +82,74 @@ exit codes: ``` 1. Print this usage message - $ python glyphIgo.py -h + $ ./glyphIgo.py -h 2. Check whether all the characters in ebook.epub can be displayed by font.ttf - $ python glyphIgo.py check -f font.ttf -e ebook.epub + $ ./glyphIgo.py check -f font.ttf -e ebook.epub 3. As above, but use font_glyph_list.txt containing a list of decimal codepoints for the font glyphs - $ python glyphIgo.py check -g font_glyph_list.txt -e ebook.epub + $ ./glyphIgo.py check -g font_glyph_list.txt -e ebook.epub 4. As above, but sort missing characters (if any) by their count (in ebook.epub) instead of by Unicode codepoint - $ python glyphIgo.py check -f font.ttf -e ebook.epub -s + $ ./glyphIgo.py check -f font.ttf -e ebook.epub -s 5. As above, but also create missing.epub containing the list of missing Unicode characters - $ python glyphIgo.py check -f font.ttf -e ebook.epub -u -o missing.epub + $ ./glyphIgo.py check -f font.ttf -e ebook.epub -u -o missing.epub 6. Convert font.ttf (TTF) into font.otf (OTF) - $ python glyphIgo.py convert -f font.ttf -o font.otf + $ ./glyphIgo.py convert -f font.ttf -o font.otf 7. Count the number of characters in ebook.epub - $ python glyphIgo.py count -e ebook.epub + $ ./glyphIgo.py count -e ebook.epub 8. As above, but preserve tags - $ python glyphIgo.py count -e ebook.epub --preserve + $ ./glyphIgo.py count -e ebook.epub --preserve 9. Print the list of glyphs in font.ttf - $ python glyphIgo.py list -f font.ttf + $ ./glyphIgo.py list -f font.ttf 10. As above, but just output the decimal codepoints - $ python glyphIgo.py list -f font.ttf -q + $ ./glyphIgo.py list -f font.ttf -q 11. Print the list of characters in ebook.epub - $ python glyphIgo.py list -e ebook.epub + $ ./glyphIgo.py list -e ebook.epub 12. As above, but also create list.epub containing the list of Unicode characters - $ python glyphIgo.py list -e ebook.epub -u -o list.epub + $ ./glyphIgo.py list -e ebook.epub -u -o list.epub 13. Print the list of characters in page.xhtml - $ python glyphIgo.py list -p page.xhtml + $ ./glyphIgo.py list -p page.xhtml 14. Print the list of characters in the range 0x2200-0x22ff (Mathematical Operators) - $ python glyphIgo.py list -r 0x2200-0x22ff - $ python glyphIgo.py list -r "Mathematical Operators" + $ ./glyphIgo.py list -r 0x2200-0x22ff + $ ./glyphIgo.py list -r "Mathematical Operators" 15. Print the range and name of Unicode blocks - $ python glyphIgo.py list --blocks + $ ./glyphIgo.py list --blocks 16. Lookup for information for Unicode character - $ python glyphIgo.py lookup -c 8253 - $ python glyphIgo.py lookup -c 0x203d - $ python glyphIgo.py lookup -c ‽ - $ python glyphIgo.py lookup -c "INTERROBANG" + $ ./glyphIgo.py lookup -c 8253 + $ ./glyphIgo.py lookup -c 0x203d + $ ./glyphIgo.py lookup -c ‽ + $ ./glyphIgo.py lookup -c "INTERROBANG" 17. As above, but print compact output - $ python glyphIgo.py lookup --compact -c 8253 - $ python glyphIgo.py lookup --compact -c 0x203d - $ python glyphIgo.py lookup --compact -c ‽ - $ python glyphIgo.py lookup --compact -c "INTERROBANG" + $ ./glyphIgo.py lookup --compact -c 8253 + $ ./glyphIgo.py lookup --compact -c 0x203d + $ ./glyphIgo.py lookup --compact -c ‽ + $ ./glyphIgo.py lookup --compact -c "INTERROBANG" 18. Heuristic lookup for information for Unicode characters which are Greek omega letters with oxia - $ python glyphIgo.py lookup --heuristic -c "GREEK OMEGA OXIA" + $ ./glyphIgo.py lookup --heuristic -c "GREEK OMEGA OXIA" 19. (De)obfuscate font.otf into obf.font.otf using the given id and the IDPF algorithm - $ python glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf + $ ./glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf 20. As above, but use Adobe algorithm - $ python glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf --adobe + $ ./glyphIgo.py obfuscate -f font.otf -i "urn:uuid:9a0ca9ab-9e33-4181-b2a3-e7f2ceb8e9bd" -o obf.font.otf --adobe 21. Subset font.ttf into min.font.otf by copying only the glyphs appearing in ebook.epub - $ python glyphIgo.py subset -f font.ttf -e ebook.epub -o min.font.otf + $ ./glyphIgo.py subset -f font.ttf -e ebook.epub -o min.font.otf ``` Please see [OUTPUT.md](OUTPUT.md) for usage examples with their actual output. @@ -162,6 +162,13 @@ Please see [OUTPUT.md](OUTPUT.md) for usage examples with their actual output. Previous versions, hosted in a Google Code repo, were released under the GNU GPL 3 License. +## Autocompletion + +**glyphIgo** uses `argcomplete` for autocompleting options/filenames. +Please refer to the [`argcomplete` documentation](https://argcomplete.readthedocs.org/en/latest/) +for directions on how to enable it. + + ## Technical Notes **glyphIgo** requires Python 2.7 (or later Python 2.x), and Python modules: diff --git a/src/genEPUB.py b/src/genEPUB.py old mode 100644 new mode 100755 diff --git a/src/glyphIgo.py b/src/glyphIgo.py old mode 100644 new mode 100755 index 774be47..4acaf2b --- a/src/glyphIgo.py +++ b/src/glyphIgo.py @@ -1,16 +1,18 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +# PYTHON_ARGCOMPLETE_OK __license__ = 'MIT' __author__ = 'Alberto Pettarin (alberto@albertopettarin.it)' __copyright__ = '2012-2014 Alberto Pettarin (alberto@albertopettarin.it)' -__version__ = 'v3.0.1' -__date__ = '2014-10-08' +__version__ = 'v3.0.2' +__date__ = '2014-10-19' __description__ = 'glyphIgo is a Swiss Army knife for dealing with fonts and EPUB eBooks' ### BEGIN changelog ### # +# 3.0.2 2014-10-19 Support for bash/zsh autocompletion via argcomplete # 3.0.1 2014-10-08 Better hex/dec char lookup, added range option to list command # 3.0.0 2014-07-31 Heavy code refactoring, switched to argparse, changed CLI names # 2.0.3 2014-07-29 Font obfuscation/deobfuscation @@ -42,7 +44,12 @@ ### END changelog ### -#import argcomplete + +try: + import argcomplete +except ImportError: + pass + import argparse import codecs import collections @@ -418,7 +425,7 @@ def __get_examples_string(self): n = trailing_characters + " " * (tot - len(n)) + n s += n + number_separator + msg + "\n" for c in cmd: - s += trailing_characters + (" " * (tot + len(number_separator))) + "$ python " + sys.argv[0] + " " + c + "\n" + s += trailing_characters + (" " * (tot + len(number_separator))) + "$ " + sys.argv[0] + " " + c + "\n" s += "\n" else: s += trailing_characters + "\n" @@ -429,7 +436,7 @@ def __get_optional_parameters(self): return self.OPTIONAL_PARAMETERS def __get_usage(self): - return "$ python " + sys.argv[0] + " " + "|".join(self.COMMAND_ALL) + " [options]" + return "$ " + sys.argv[0] + " " + "|".join(self.COMMAND_ALL) + " [options]" def __get_version(self): return self.VERSION @@ -476,7 +483,13 @@ def get_arguments(self): default=argparse.SUPPRESS ) - # TODO investigate argcomplete.autocomplete(parser) + # try using argcomplete + try: + argcomplete.autocomplete(parser) + except: + pass + + # parse arguments args = parser.parse_args() # standard ArgumentParser checker is cumbersome and limited