fix: method call in console_scripts
This commit is contained in:
2
Makefile
2
Makefile
@@ -8,7 +8,7 @@ install:
|
|||||||
uninstall:
|
uninstall:
|
||||||
python3 -m pip uninstall abcddb2vcard
|
python3 -m pip uninstall abcddb2vcard
|
||||||
rm -rf ./*.egg-info/
|
rm -rf ./*.egg-info/
|
||||||
-rm -i "$$(which abcddb2vcard)" "$$(which vcard2img)"
|
@-rm -i "$$(which abcddb2vcard)" "$$(which vcard2img)"
|
||||||
|
|
||||||
dist: setup.py abcddb2vcard/*
|
dist: setup.py abcddb2vcard/*
|
||||||
[ -z "$${VIRTUAL_ENV}" ] # you can not do this inside a virtual environment.
|
[ -z "$${VIRTUAL_ENV}" ] # you can not do this inside a virtual environment.
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
'''
|
'''
|
||||||
Convert AddressBook database (.abcddb) to Contacts VCards file (.vcf)
|
Convert AddressBook database (.abcddb) to Contacts VCards file (.vcf)
|
||||||
'''
|
'''
|
||||||
__version__ = '1.0.0'
|
__version__ = '1.0.1'
|
||||||
|
|
||||||
from .ABCDDB import ABCDDB
|
from .ABCDDB import ABCDDB
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from . import abcddb2vcard # execute sub-module code
|
from .abcddb2vcard import main
|
||||||
|
|
||||||
|
main()
|
||||||
|
|||||||
@@ -11,38 +11,41 @@ try:
|
|||||||
except ImportError: # fallback if not run as module
|
except ImportError: # fallback if not run as module
|
||||||
from ABCDDB import ABCDDB # type: ignore[import, no-redef]
|
from ABCDDB import ABCDDB # type: ignore[import, no-redef]
|
||||||
|
|
||||||
|
|
||||||
DB_FILE = str(Path.home().joinpath(
|
DB_FILE = str(Path.home().joinpath(
|
||||||
'Library', 'Application Support', 'AddressBook', 'AddressBook-v22.abcddb'))
|
'Library', 'Application Support', 'AddressBook', 'AddressBook-v22.abcddb'))
|
||||||
|
|
||||||
cli = ArgumentParser(description=__doc__)
|
|
||||||
cli.add_argument('output', type=str, metavar='outfile.vcf',
|
|
||||||
help='VCard output file.')
|
|
||||||
cli.add_argument('-f', '--force', action='store_true',
|
|
||||||
help='Overwrite existing output file.')
|
|
||||||
cli.add_argument('-i', '--input', type=str, metavar='AddressBook.abcddb',
|
|
||||||
default=DB_FILE, help='Specify another abcddb input file.'
|
|
||||||
' Default: ' + DB_FILE)
|
|
||||||
args = cli.parse_args()
|
|
||||||
|
|
||||||
# check input args
|
def main() -> None:
|
||||||
if not os.path.isfile(args.input):
|
cli = ArgumentParser(description=__doc__)
|
||||||
print('AddressBook "{}" does not exist.'.format(args.input),
|
cli.add_argument('output', type=str, metavar='outfile.vcf',
|
||||||
file=sys.stderr)
|
help='VCard output file.')
|
||||||
exit(1)
|
cli.add_argument('-f', '--force', action='store_true',
|
||||||
elif not os.path.isdir(os.path.dirname(args.output) or os.curdir):
|
help='Overwrite existing output file.')
|
||||||
print('Output parent directory does not exist.', file=sys.stderr)
|
cli.add_argument('-i', '--input', type=str, metavar='AddressBook.abcddb',
|
||||||
exit(1)
|
default=DB_FILE, help='Specify another abcddb input file.'
|
||||||
elif os.path.isfile(args.output) and not args.force:
|
' Default: ' + DB_FILE)
|
||||||
print('Output file already exist. Use -f to force overwrite.',
|
args = cli.parse_args()
|
||||||
file=sys.stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# perform export
|
# check input args
|
||||||
contacts = ABCDDB.load(args.input)
|
if not os.path.isfile(args.input):
|
||||||
with open(args.output, 'w') as f:
|
print('AddressBook "{}" does not exist.'.format(args.input),
|
||||||
for rec in contacts:
|
file=sys.stderr)
|
||||||
f.write(rec.makeVCard())
|
exit(1)
|
||||||
print(len(contacts), 'contacts.')
|
elif not os.path.isdir(os.path.dirname(args.output) or os.curdir):
|
||||||
|
print('Output parent directory does not exist.', file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
elif os.path.isfile(args.output) and not args.force:
|
||||||
|
print('Output file already exist. Use -f to force overwrite.',
|
||||||
|
file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
exit()
|
# perform export
|
||||||
|
contacts = ABCDDB.load(args.input)
|
||||||
|
with open(args.output, 'w') as f:
|
||||||
|
for rec in contacts:
|
||||||
|
f.write(rec.makeVCard())
|
||||||
|
print(len(contacts), 'contacts.')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
@@ -7,48 +7,53 @@ import sys
|
|||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
from argparse import ArgumentParser, FileType
|
from argparse import ArgumentParser, FileType
|
||||||
|
|
||||||
cli = ArgumentParser(description=__doc__)
|
|
||||||
cli.add_argument('input', type=FileType('r'), metavar='infile.vcf',
|
|
||||||
help='VCard input file.')
|
|
||||||
cli.add_argument('outdir', type=str, help='Output directory.')
|
|
||||||
args = cli.parse_args()
|
|
||||||
|
|
||||||
# check input args
|
def main() -> None:
|
||||||
if not os.path.isdir(os.path.dirname(args.outdir) or os.curdir):
|
cli = ArgumentParser(description=__doc__)
|
||||||
print('Output parent directory does not exist.', file=sys.stderr)
|
cli.add_argument('input', type=FileType('r'), metavar='infile.vcf',
|
||||||
exit(1)
|
help='VCard input file.')
|
||||||
|
cli.add_argument('outdir', type=str, help='Output directory.')
|
||||||
|
args = cli.parse_args()
|
||||||
|
|
||||||
os.makedirs(args.outdir, exist_ok=True)
|
# check input args
|
||||||
|
if not os.path.isdir(os.path.dirname(args.outdir) or os.curdir):
|
||||||
|
print('Output parent directory does not exist.', file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
# perform export
|
os.makedirs(args.outdir, exist_ok=True)
|
||||||
c1 = 0
|
|
||||||
c2 = 0
|
# perform export
|
||||||
name = ''
|
c1 = 0
|
||||||
img = ''
|
c2 = 0
|
||||||
collect = False
|
name = ''
|
||||||
for line in args.input.readlines():
|
img = ''
|
||||||
line = line.rstrip()
|
collect = False
|
||||||
if line == 'BEGIN:VCARD':
|
for line in args.input.readlines():
|
||||||
c1 += 1
|
line = line.rstrip()
|
||||||
name = ''
|
if line == 'BEGIN:VCARD':
|
||||||
img = ''
|
c1 += 1
|
||||||
collect = False
|
name = ''
|
||||||
elif line.startswith('FN:'):
|
img = ''
|
||||||
name = line.split(':', 1)[1]
|
|
||||||
elif line.startswith('PHOTO;'):
|
|
||||||
img = line.split(':', 1)[1]
|
|
||||||
collect = True
|
|
||||||
elif collect:
|
|
||||||
if line[0] == ' ':
|
|
||||||
img += line[1:]
|
|
||||||
else:
|
|
||||||
collect = False
|
collect = False
|
||||||
if line == 'END:VCARD' and img:
|
elif line.startswith('FN:'):
|
||||||
c2 += 1
|
name = line.split(':', 1)[1]
|
||||||
name = name.replace('\\,', ',').replace('\\;', ';').replace(
|
elif line.startswith('PHOTO;'):
|
||||||
'/', '-')
|
img = line.split(':', 1)[1]
|
||||||
with open(os.path.join(args.outdir, name + '.jpg'), 'wb') as fw:
|
collect = True
|
||||||
fw.write(b64decode(img))
|
elif collect:
|
||||||
|
if line[0] == ' ':
|
||||||
|
img += line[1:]
|
||||||
|
else:
|
||||||
|
collect = False
|
||||||
|
if line == 'END:VCARD' and img:
|
||||||
|
c2 += 1
|
||||||
|
name = name.replace('\\,', ',').replace('\\;', ';').replace(
|
||||||
|
'/', '-')
|
||||||
|
with open(os.path.join(args.outdir, name + '.jpg'), 'wb') as fw:
|
||||||
|
fw.write(b64decode(img))
|
||||||
|
|
||||||
print(c1, 'contacts.', c2, 'images.')
|
print(c1, 'contacts.', c2, 'images.')
|
||||||
exit()
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -15,8 +15,8 @@ setup(
|
|||||||
packages=['abcddb2vcard'],
|
packages=['abcddb2vcard'],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'abcddb2vcard=abcddb2vcard.abcddb2vcard',
|
'abcddb2vcard=abcddb2vcard.abcddb2vcard:main',
|
||||||
'vcard2img=abcddb2vcard.vcard2img',
|
'vcard2img=abcddb2vcard.vcard2img:main',
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|||||||
Reference in New Issue
Block a user