PK njM contactList/VERSION0.1.0
PK ljMK; contactList/__init__.py#
# Copyright 2018 Russell Smiley
#
# This file is part of contactList.
#
# contactList is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# contactList is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with contactList. If not, see .
#
"""A Python 3 framework for constructing, managing and organising email addresses in YAML format.
"""
import os
here = os.path.dirname( __file__ )
with open( os.path.join( here, 'VERSION' ) ) as versionFile :
version = versionFile.read()
__version__ = version.strip()
from contactList.contacts.contact import ContactData
PK ljMe contactList/entry.py#
# Copyright 2018 Russell Smiley
#
# This file is part of contactList.
#
# contactList is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# contactList is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with contactList. If not, see .
#
"""
Define contact management entrypoint.
"""
import sys
from .arguments import ContactsOptions
from .contacts import Contacts
def main( commandLineArguments ) :
debugMode = False
try :
managerOptions = ContactsOptions.from_arguments( commandLineArguments )
debugMode = managerOptions.debug
contacts = Contacts.from_yamlFile( filename = managerOptions.contactsFile )
contacts.applyAction( managerOptions )
contacts.to_yamlFile( filename = managerOptions.contactsFile )
except Exception as e :
if not debugMode :
print( str( e ), file = sys.stderr )
# Exit with non-zero status (dirty).
sys.exit( 1 )
else :
raise
def entryPoint() :
"""
Flit entrypoint. The flit entrypoint must not have any arguments, so here it just calls ``main`` with
``sys.argv`` argument.
"""
main( sys.argv[ 1 : ] )
if __name__ == '__main__' :
main( sys.argv[ 1 : ] )
PK ljM ! contactList/arguments/__init__.py#
# Copyright 2018 Russell Smiley
#
# This file is part of contactList.
#
# contactList is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# contactList is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with contactList. If not, see .
#
"""
Command line argument parsing implementation.
"""
from .top import ContactsOptions
PK ljMI0 contactList/arguments/top.py#
# Copyright 2018 Russell Smiley
#
# This file is part of contactList.
#
# contactList is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# contactList is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with contactList. If not, see .
#
"""
Top level command line argument parsing configuration.
"""
from .base import BadArgument, CommandTree
from .cluster import CLUSTER_SUBCOMMAND_GRAPH
from .email import EMAIL_SUBCOMMAND_GRAPH
from .group import GROUP_SUBCOMMAND_GRAPH
class ContactsOptions :
"""
Top level command line argument parsing configuration.
"""
__DEFAULT_FILE = 'contacts.yml'
__CONTACTSFILE_ARGUMENT_GRAPH = {
'names' : [ '--file', '-f', ],
'options' : {
'default' : __DEFAULT_FILE,
'dest' : 'contactsFile',
'help' : 'Contacts file to manage (default ''{0}'')'.format( __DEFAULT_FILE ),
'type' : str
}
}
__DEBUG_ARGUMENT_GRAPH = {
'names' : [ '--debug', '-d', ],
'options' : {
'action' : 'store_true',
'help' : 'Enable exception stack trace reporting to command line',
}
}
__CONTACTS_COMMAND_GRAPH = {
'arguments' : [
__CONTACTSFILE_ARGUMENT_GRAPH,
__DEBUG_ARGUMENT_GRAPH,
],
'options' : {
'dest' : 'activeSubcommand',
},
'subcommands' : [
CLUSTER_SUBCOMMAND_GRAPH,
EMAIL_SUBCOMMAND_GRAPH,
GROUP_SUBCOMMAND_GRAPH,
],
}
def __init__( self ) :
self.__commandTree = CommandTree( specification = self.__CONTACTS_COMMAND_GRAPH )
self.__parsedArguments = None
def parse( self, commandLineArguments: list ) :
"""
Parse command line arguments.
:param commandLineArguments:
:return:
"""
self.__parsedArguments = self.__commandTree.parse( commandLineArguments )
if not self.__parsedArguments.activeSubcommand :
raise BadArgument( 'Must specify a contact list operation' )
def __getattr__( self, item ) :
"""
From parsed arguments, recover the items from an `argparse.Namespace` object.
:param item: parsed argument item name.
:return: Parsed argument item.
"""
return getattr( self.__parsedArguments, item )
@classmethod
def from_arguments( cls, commandLineArguments: list ) :
options = cls()
options.parse( commandLineArguments )
return options
PK ljMi^Y Y &