def _get_install_config(read_config): install_config = None if read_config: config_filename = get_home_dir_path('.config/logit') try: with open(config_filename, 'r') as f: install_config = json.load(f) except (IOError, ValueError): pass if install_config is None: # Create a new id for this installation install_config = { 'uuid': str(uuid.uuid4()), 'config_time': datetime.utcnow().isoformat(), } make_sure_path_exists(dirname(config_filename)) with open(config_filename, 'w') as f: json.dump(install_config, f, sort_keys=True, indent=4) assert install_config return install_config
def get_arg_parser(): """Get the argument parser""" parser = argparse.ArgumentParser() parser.add_argument( '--log', dest='logit_filename', default=get_home_dir_path(LOGIT_FILENAME), help='Specify the location to store the actual log file.', ) parser.add_argument( '--todo', dest='todo_list', action='store_true', default=False, help='Launch interactive todo tracker', ) parser.add_argument( '--check', dest='check', action='store_true', default=False, help='Test the integrity of the logit.txt file', ) parser.add_argument( '--back-date', dest='back_date', action='store', default=None, help='Backdate a log entry. --backdate 2014-10-03', ) parser.add_argument( '--show_recent_week', dest='show_recent_week', action='store_true', default=False, help='Connect to S3 and show the most recent week of log info.', ) parser.add_argument( '--backup', dest='backup', action='store_true', default=False, help='Backup the logit.txt file to an S3 bucket', ) parser.add_argument( '--s3-bucket', dest='s3_bucket', action='store', help='When running backup, use this AWS access key id', ) parser.add_argument( '--aws-access-key-id', dest='aws_access_key_id', action='store', default=None, help='When running backup, use this AWS access key id', ) parser.add_argument( '--aws-secret-access-key', dest='aws_secret_access_key', action='store', default=None, help='When running backup, use this AWS access key id', ) parser.add_argument( '-c', dest='category', help='Message category', ) parser.add_argument( '-m', dest='message', help='Log message', ) parser.add_argument( '-l', dest='list', action='store_true', default=False, help='Print the current logit log', ) parser.add_argument( '-M', dest='merge', action='store_true', default=False, help='Merge all S3 logs into this log.', ) parser.add_argument( '--version', dest='version', action='store_true', default=False, help='Print the current logit version ({})'.format(get_version()), ) parser.add_argument( '--encrypt-all', dest='encrypt_all', action='store_true', default=False, help=('Go back through prior locally stored logit entries, and ' 'encrypt them.'), ) return parser
from os.path import dirname from attrdict import AttrDict import boto from boto.s3.key import Key from logit.crypt import encrypt_json, get_secret_key, decrypt_json from logit.utils import (get_home_dir_path, get_terminal_size, bcolors, unique_id_from_entry, make_sure_path_exists, get_console_input) LOGIT_FILENAME = 'logit.txt' if __name__ == '__main__': logging.basicConfig(filename=get_home_dir_path('.logit.log'), level=logging.INFO) logger = logging.getLogger('logit') def get_categories(): """Get categories.""" return { 'note': { 'description': 'Just a note', }, 'todo': { 'description': 'TODO', 'track_completion': True, },