khard.khard module

Main application logic of khard includeing command line handling

khard.khard.add_email_subcommand(text, abooks)

Add a new email address to contacts, creating new contacts if necessary.

Parameters:
  • text (str) – the input text to search for the new email
  • abooks (list of address_book.AddressBook) – the addressbooks that were selected on the command line
Returns:

None

Return type:

None

khard.khard.birthdays_subcommand(vcard_list, parsable)

Print birthday contact table.

Parameters:
  • vcard_list (list of carddav_object.CarddavObject) – the vcards to search for matching entries which should be printed
  • parsable (bool) – machine readable output: columns devided by tabulator ( )
Returns:

None

Return type:

None

khard.khard.choose_address_book_from_list(header_string, address_book_list)
khard.khard.choose_vcard_from_list(header_string, vcard_list, include_none=False)
khard.khard.copy_contact(contact, target_address_book, delete_source_contact)
khard.khard.copy_or_move_subcommand(action, vcard_list, target_address_book_list)

Copy or move a contact to a different address book.

Action:

the string “copy” or “move” to indicate what to do

Parameters:
  • vcard_list (list of carddav_object.CarddavObject) – the contact list from which to select one for the action
  • target_address_book_list (list(addressbook.AddressBook)) – the list of target address books
Returns:

None

Return type:

None

khard.khard.create_new_contact(address_book)
khard.khard.edit(*filenames, merge=False)

Edit the given files with the configured editor or merge editor

khard.khard.email_subcommand(search_terms, vcard_list, parsable, remove_first_line)

Print a mail client friendly contacts table that is compatible with the default format used by mutt. Output format:

single line of text
email_address   name    type
email_address   name    type
[...]
Parameters:
  • search_terms (str) – used as search term to filter the contacts before printing
  • vcard_list (list of carddav_object.CarddavObject) – the vcards to search for matching entries which should be printed
  • parsable (bool) – machine readable output: columns devided by tabulator ( )
  • remove_first_line (bool) – remove first line (searching for ‘’ …)
Returns:

None

Return type:

None

khard.khard.generate_contact_list(args)

TODO: Docstring for generate_contact_list.

Parameters:args (argparse.Namespace) – the command line arguments
Returns:the contacts for further processing (TODO)
Return type:list(TODO)
khard.khard.get_contact_list_by_user_selection(address_books, search, strict_search)

returns a list of CarddavObject objects :param address_books: list of selected address books :type address_books: list(address_book.AddressBook) :param search: filter contact list :type search: str :param strict_search: if True, search only in full name field :type strict_search: bool :returns: list of CarddavObject objects :rtype: list(CarddavObject)

khard.khard.get_contacts(address_books, query, method='all', reverse=False, group=False, sort='first_name')

Get a list of contacts from one or more address books.

Parameters:
  • address_books (list(address_book.AddressBook)) – the address books to search
  • query (str) – a search query to select contacts
  • method (str) – the search method, one of “all”, “name” or “uid”
  • reverse (bool) – reverse the order of the returned contacts
  • group (bool) – group results by address book
  • sort (str) – the field to use for sorting, one of “first_name”, “last_name”, “formatted_name”
Returns:

contacts from the address_books that match the query

Return type:

list(CarddavObject)

khard.khard.list_address_books(address_book_list)
khard.khard.list_birthdays(birthday_list)
khard.khard.list_contacts(vcard_list)
khard.khard.list_email_addresses(email_address_list)
khard.khard.list_phone_numbers(phone_number_list)
khard.khard.list_post_addresses(post_address_list)
khard.khard.list_subcommand(vcard_list, parsable)

Print a user friendly contacts table.

Parameters:
  • vcard_list (list of carddav_object.CarddavObject) – the vcards to print
  • parsable (bool) – machine readable output: columns devided by tabulator ( )
Returns:

None

Return type:

None

khard.khard.load_address_books(names, config, search_queries)

Load all address books with the given names from the config.

Parameters:
  • names (list(str)) – the address books to load
  • config (config.Config) – the config instance to use when looking up address books
  • search_queries (dict) – a mapping of address book names to search queries
Yields:

the loaded address books

Ytype:

addressbook.AddressBook

khard.khard.main(argv=['-M', 'html', 'source', 'build'])
khard.khard.merge_existing_contacts(source_contact, target_contact, delete_source_contact)
khard.khard.merge_subcommand(vcard_list, selected_address_books, search_terms, target_uid)

Merge two contacts into one.

Parameters:
  • vcard_list (list of carddav_object.CarddavObject) – the vcards from which to choose contacts for mergeing
  • selected_address_books (list(addressbook.AddressBook)) – the addressbooks to use to find the target contact
  • search_terms (str) – the search terms to find the target contact
  • target_uid (str) – the uid of the target contact or empty
Returns:

None

Return type:

None

khard.khard.modify_existing_contact(old_contact)
khard.khard.modify_subcommand(selected_vcard, input_from_stdin_or_file, open_editor, source=False)

Modify a contact in an external editor.

Parameters:
  • selected_vcard (carddav_object.CarddavObject) – the contact to modify
  • input_from_stdin_or_file (str) – new data from stdin (or a file) that should be incorperated into the contact, this should be a yaml formatted string
  • open_editor (bool) – whether to open the new contact in the edior after creation
  • source (bool) – edit the source file or a yaml version?
Returns:

None

Return type:

None

khard.khard.new_subcommand(selected_address_books, input_from_stdin_or_file, open_editor)

Create a new contact.

Parameters:
  • selected_address_books (list of address_book.AddressBook) – a list of addressbooks that were selected on the command line
  • input_from_stdin_or_file (str) – the data for the new contact as a yaml formatted string
  • open_editor (bool) – whether to open the new contact in the edior after creation
Returns:

None

Return type:

None

khard.khard.phone_subcommand(search_terms, vcard_list, parsable)

Print a phone application friendly contact table.

Parameters:
  • search_terms (str) – used as search term to filter the contacts before printing
  • vcard_list (list of carddav_object.CarddavObject) – the vcards to search for matching entries which should be printed
  • parsable (bool) – machine readable output: columns devided by tabulator ( )
Returns:

None

Return type:

None

khard.khard.post_address_subcommand(search_terms, vcard_list, parsable)

Print a contact table. with all postal / mailing addresses

Parameters:
  • search_terms (str) – used as search term to filter the contacts before printing
  • vcard_list (list of carddav_object.CarddavObject) – the vcards to search for matching entries which should be printed
  • parsable (bool) – machine readable output: columns devided by tabulator ( )
Returns:

None

Return type:

None

khard.khard.prepare_search_queries(args)

Prepare the search query string from the given command line args.

Each address book can get a search query string to filter vcards befor loading them. Depending on the question if the address book is used for source or target searches different regexes have to be combined into one search string.

Parameters:args (argparse.Namespace) – the parsed command line
Returns:a dict mapping abook names to their loading queries, if the query is None it means that all cards should be loaded
Return type:dict(str:str or None)
khard.khard.remove_subcommand(selected_vcard, force)

Remove a contact from the addressbook.

Parameters:
Returns:

None

Return type:

None

khard.khard.write_temp_file(text='')

Create a new temporary file and write some initial text to it.

Parameters:text (str) – the text to write to the temp file
Returns:the file name of the newly created temp file
Return type:str