예제 #1
0
파일: install.py 프로젝트: legacy-code/jrnl
def install_jrnl(config_path='~/.jrnl_config'):
    def autocomplete(text, state):
        expansions = glob.glob(
            os.path.expanduser(os.path.expandvars(text)) + '*')
        expansions = [e + "/" if os.path.isdir(e) else e for e in expansions]
        expansions.append(None)
        return expansions[state]

    #readline.set_completer_delims(' \t\n;')
    #readline.parse_and_bind("tab: complete")
    #readline.set_completer(autocomplete)

    # Where to create the journal?
    path_query = 'Path to your journal file (leave blank for ~/journal.txt): '
    journal_path = util.py23_input(path_query).strip() or os.path.expanduser(
        '~/journal.txt')
    default_config['journals']['default'] = os.path.expanduser(
        os.path.expandvars(journal_path))

    # Encrypt it?
    #if module_exists("Crypto"):
    #    password = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
    #    if password:
    #        default_config['encrypt'] = True
    #        if util.yesno("Do you want to store the password in your keychain?", default=True):
    #            util.set_keychain("default", password)
    #        else:
    #            util.set_keychain("default", None)
    #        print("Journal will be encrypted.")
    #else:
    #    password = None
    #    print("PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org or with 'pip install pycrypto' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text.")
    #

    path = os.path.split(default_config['journals']['default'])[
        0]  # If the folder doesn't exist, create it
    try:
        os.makedirs(path)
    except OSError:
        pass

    if not os.path.isdir(
            path
    ):  # if it's a directory and exists (e.g. a DayOne journal, let it be)
        open(default_config['journals']['default'],
             'a').close()  # Touch to make sure it's there

    # Write config to ~/.jrnl_conf
    with open(config_path, 'w') as f:
        json.dump(default_config, f, indent=2)
    config = default_config
    #if password:
    #    config['password'] = password
    return config
예제 #2
0
def install_jrnl(config_path='~/.jrnl_config'):
    def autocomplete(text, state):
        expansions = glob.glob(os.path.expanduser(text) + '*')
        expansions = [e + "/" if os.path.isdir(e) else e for e in expansions]
        expansions.append(None)
        return expansions[state]

    readline.set_completer_delims(' \t\n;')
    readline.parse_and_bind("tab: complete")
    readline.set_completer(autocomplete)

    # Where to create the journal?
    path_query = 'Path to your journal file (leave blank for ~/journal.txt): '
    journal_path = util.py23_input(path_query).strip() or os.path.expanduser(
        '~/journal.txt')
    default_config['journals']['default'] = os.path.expanduser(journal_path)

    # Encrypt it?
    if module_exists("Crypto"):
        password = getpass.getpass(
            "Enter password for journal (leave blank for no encryption): ")
        if password:
            default_config['encrypt'] = True
            print("Journal will be encrypted.")
            print(
                "If you want to, you can store your password in .jrnl_config and will never be bothered about it again."
            )
    else:
        password = None
        print(
            "PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org and run 'jrnl --encrypt'. For now, your journal will be stored in plain text."
        )

    # Use highlighting:
    if not module_exists("colorama"):
        print(
            "colorama not found. To turn on highlighting, install colorama and set highlight to true in your .jrnl_conf."
        )
        default_config['highlight'] = False

    open(default_config['journals']['default'],
         'a').close()  # Touch to make sure it's there

    # Write config to ~/.jrnl_conf
    with open(config_path, 'w') as f:
        json.dump(default_config, f, indent=2)
    config = default_config
    if password:
        config['password'] = password
    return config
예제 #3
0
파일: install.py 프로젝트: bentsai/jrnl
def install_jrnl(config_path='~/.jrnl_config'):
    def autocomplete(text, state):
        expansions = glob.glob(os.path.expanduser(text)+'*')
        expansions = [e+"/" if os.path.isdir(e) else e for e in expansions]
        expansions.append(None)
        return expansions[state]
    readline.set_completer_delims(' \t\n;')
    readline.parse_and_bind("tab: complete")
    readline.set_completer(autocomplete)

    # Where to create the journal?
    path_query = 'Path to your journal file (leave blank for ~/journal.txt): '
    journal_path = util.py23_input(path_query).strip() or os.path.expanduser('~/journal.txt')
    default_config['journals']['default'] = os.path.expanduser(journal_path)

    # Encrypt it?
    if module_exists("Crypto"):
        password = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
        if password:
            default_config['encrypt'] = True
            if util.yesno("Do you want to store the password in your keychain?", default=True):
                util.set_keychain("default", password)
            else:
                util.set_keychain("default", None)
            print("Journal will be encrypted.")
    else:
        password = None
        print("PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org or with 'pip install pycrypto' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text.")

    # Use highlighting:
    if not module_exists("colorama"):
        print("colorama not found. To turn on highlighting, install colorama and set highlight to true in your .jrnl_conf.")
        default_config['highlight'] = False

    open(default_config['journals']['default'], 'a').close()  # Touch to make sure it's there

    # Write config to ~/.jrnl_conf
    with open(config_path, 'w') as f:
        json.dump(default_config, f, indent=2)
    config = default_config
    if password:
        config['password'] = password
    return config
예제 #4
0
파일: install.py 프로젝트: rockitbaby/jrnl
def install_jrnl(config_path="~/.jrnl_config"):
    def autocomplete(text, state):
        expansions = glob.glob(os.path.expanduser(text) + "*")
        expansions = [e + "/" if os.path.isdir(e) else e for e in expansions]
        expansions.append(None)
        return expansions[state]

    readline.set_completer_delims(" \t\n;")
    readline.parse_and_bind("tab: complete")
    readline.set_completer(autocomplete)

    # Where to create the journal?
    path_query = "Path to your journal file (leave blank for ~/journal.txt): "
    journal_path = util.py23_input(path_query).strip() or os.path.expanduser("~/journal.txt")
    default_config["journals"]["default"] = os.path.expanduser(journal_path)

    # Encrypt it?
    if module_exists("Crypto"):
        password = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
        if password:
            default_config["encrypt"] = True
            if util.yesno("Do you want to store the password in your keychain?", default=True):
                util.set_keychain("default", password)
            else:
                util.set_keychain("default", None)
            print("Journal will be encrypted.")
    else:
        password = None
        print(
            "PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org or with 'pip install pycrypto' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text."
        )

    open(default_config["journals"]["default"], "a").close()  # Touch to make sure it's there

    # Write config to ~/.jrnl_conf
    with open(config_path, "w") as f:
        json.dump(default_config, f, indent=2)
    config = default_config
    if password:
        config["password"] = password
    return config
예제 #5
0
파일: jrnl.py 프로젝트: reedwade/jrnl
def cli():
    if not os.path.exists(CONFIG_PATH):
        config = install.install_jrnl(CONFIG_PATH)
    else:
        with open(CONFIG_PATH) as f:
            config = json.load(f)
        install.update_config(config, config_path=CONFIG_PATH)

    original_config = config.copy()
    # check if the configuration is supported by available modules
    if config['encrypt'] and not PYCRYPTO:
        print(
            "According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org."
        )
        sys.exit(-1)

    args = parse_args()

    # If the first textual argument points to a journal file,
    # use this!
    journal_name = args.text[0] if (
        args.text and args.text[0] in config['journals']) else 'default'
    if journal_name is not 'default':
        args.text = args.text[1:]
    journal_conf = config['journals'].get(journal_name)
    if type(
            journal_conf
    ) is dict:  # We can override the default config on a by-journal basis
        config.update(journal_conf)
    else:  # But also just give them a string to point to the journal file
        config['journal'] = journal_conf
    touch_journal(config['journal'])
    mode_compose, mode_export = guess_mode(args, config)

    # open journal file or folder


    if os.path.isdir(config['journal']) and ( config['journal'].endswith(".dayone") or \
        config['journal'].endswith(".dayone/")):
        journal = Journal.DayOne(**config)
    else:
        journal = Journal.Journal(**config)

    if mode_compose and not args.text:
        if config['editor']:
            raw = get_text_from_editor(config)
        else:
            raw = util.py23_input("[Compose Entry] ")
        if raw:
            args.text = [raw]
        else:
            mode_compose = False

    # Writing mode
    if mode_compose:
        raw = " ".join(args.text).strip()
        entry = journal.new_entry(raw, args.date)
        entry.starred = args.star
        print("[Entry added to {0} journal]".format(journal_name))
        journal.write()

    # Reading mode
    elif not mode_export:
        journal.filter(tags=args.text,
                       start_date=args.start_date,
                       end_date=args.end_date,
                       strict=args.strict,
                       short=args.short)
        journal.limit(args.limit)
        print(journal)

    # Various export modes
    elif args.tags:
        print_tags(journal)

    elif args.json:  # export to json
        print(exporters.to_json(journal))

    elif args.markdown:  # export to json
        print(exporters.to_md(journal))

    elif (args.encrypt is not False
          or args.decrypt is not False) and not PYCRYPTO:
        print(
            "PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org."
        )

    elif args.encrypt is not False:
        encrypt(journal, filename=args.encrypt)
        # Not encrypting to a separate file: update config!
        if not args.encrypt:
            update_config(original_config, {
                "encrypt": True,
                "password": ""
            }, journal_name)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.decrypt is not False:
        decrypt(journal, filename=args.decrypt)
        # Not decrypting to a separate file: update config!
        if not args.decrypt:
            update_config(original_config, {
                "encrypt": False,
                "password": ""
            }, journal_name)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.delete_last:
        last_entry = journal.entries.pop()
        print("[Deleted Entry:]")
        print(last_entry)
        journal.write()
예제 #6
0
파일: jrnl.py 프로젝트: alapolloni/jrnl
def cli(manual_args=None):
    if not os.path.exists(CONFIG_PATH):
        config = install.install_jrnl(CONFIG_PATH)
    else:
        with open(CONFIG_PATH) as f:
            try:
                config = json.load(f)
            except ValueError as e:
                util.prompt("[There seems to be something wrong with your jrnl config at {0}: {1}]".format(CONFIG_PATH, e.message))
                util.prompt("[Entry was NOT added to your journal]")
                sys.exit(1)
        install.upgrade_config(config, config_path=CONFIG_PATH)

    original_config = config.copy()
    # check if the configuration is supported by available modules
    if config['encrypt'] and not PYCRYPTO:
        util.prompt("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.")
        sys.exit(1)

    args = parse_args(manual_args)

    # If the first textual argument points to a journal file,
    # use this!
    journal_name = args.text[0] if (args.text and args.text[0] in config['journals']) else 'default'
    if journal_name is not 'default':
        args.text = args.text[1:]
    journal_conf = config['journals'].get(journal_name)
    if type(journal_conf) is dict:  # We can override the default config on a by-journal basis
        config.update(journal_conf)
    else:  # But also just give them a string to point to the journal file
        config['journal'] = journal_conf
    config['journal'] = os.path.expanduser(config['journal'])
    touch_journal(config['journal'])
    mode_compose, mode_export = guess_mode(args, config)

    # open journal file or folder
    if os.path.isdir(config['journal']):
        if config['journal'].strip("/").endswith(".dayone") or \
           "entries" in os.listdir(config['journal']):
            journal = Journal.DayOne(**config)
        else:
            util.prompt("[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
            sys.exit(1)
    else:
        journal = Journal.Journal(journal_name, **config)

    if mode_compose and not args.text:
        if config['editor']:
            raw = get_text_from_editor(config)
        else:
            raw = util.py23_input("[Compose Entry] ")
        if raw:
            args.text = [raw]
        else:
            mode_compose = False

    # Writing mode
    if mode_compose:
        raw = " ".join(args.text).strip()
        if util.PY2 and type(raw) is not unicode:
            raw = raw.decode(sys.getfilesystemencoding())
        entry = journal.new_entry(raw, args.date)
        entry.starred = args.star
        util.prompt("[Entry added to {0} journal]".format(journal_name))
        journal.write()
    else:
        journal.filter(tags=args.text,
                       start_date=args.start_date, end_date=args.end_date,
                       strict=args.strict,
                       short=args.short)
        journal.limit(args.limit)

    # Reading mode
    if not mode_compose and not mode_export:
        print(journal.pprint())

    # Various export modes
    elif args.tags:
        print(exporters.to_tag_list(journal))

    elif args.export is not False:
        print(exporters.export(journal, args.export, args.output))

    elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTO:
        util.prompt("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.")

    elif args.encrypt is not False:
        encrypt(journal, filename=args.encrypt)
        # Not encrypting to a separate file: update config!
        if not args.encrypt:
            update_config(original_config, {"encrypt": True}, journal_name, force_local=True)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.decrypt is not False:
        decrypt(journal, filename=args.decrypt)
        # Not decrypting to a separate file: update config!
        if not args.decrypt:
            update_config(original_config, {"encrypt": False}, journal_name, force_local=True)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.delete_last:
        last_entry = journal.entries.pop()
        util.prompt("[Deleted Entry:]")
        print(last_entry.pprint())
        journal.write()
예제 #7
0
파일: jrnl.py 프로젝트: halbtuerke/jrnl
def cli():
    if not os.path.exists(CONFIG_PATH):
        config = install.install_jrnl(CONFIG_PATH)
    else:
        with open(CONFIG_PATH) as f:
            config = json.load(f)
        install.update_config(config, config_path=CONFIG_PATH)

    original_config = config.copy()
    # check if the configuration is supported by available modules
    if config['encrypt'] and not PYCRYPTO:
        print("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.")
        sys.exit(-1)

    args = parse_args()

    # If the first textual argument points to a journal file,
    # use this!
    journal_name = args.text[0] if (args.text and args.text[0] in config['journals']) else 'default'
    if journal_name is not 'default':
        args.text = args.text[1:]
    journal_conf = config['journals'].get(journal_name)
    if type(journal_conf) is dict: # We can override the default config on a by-journal basis
        config.update(journal_conf)
    else: # But also just give them a string to point to the journal file
        config['journal'] = journal_conf
    touch_journal(config['journal'])
    mode_compose, mode_export = guess_mode(args, config)

    # open journal file or folder


    if os.path.isdir(config['journal']) and ( config['journal'].endswith(".dayone") or \
        config['journal'].endswith(".dayone/")):
        journal = Journal.DayOne(**config)
    else:
        journal = Journal.Journal(**config)


    if mode_compose and not args.text:
        if config['editor']:
            raw = get_text_from_editor(config)
        else:
            raw = util.py23_input("[Compose Entry] ")
        if raw:
            args.text = [raw]
        else:
            mode_compose = False

    # Writing mode
    if mode_compose:
        raw = " ".join(args.text).strip()
        entry = journal.new_entry(raw, args.date)
        entry.starred = args.star
        print("[Entry added to {0} journal]".format(journal_name))
        journal.write()

    # Reading mode
    elif not mode_export:
        journal.filter(tags=args.text,
                       start_date=args.start_date, end_date=args.end_date,
                       strict=args.strict,
                       short=args.short)
        journal.limit(args.limit)
        print(journal)

    # Various export modes
    elif args.tags:
        print_tags(journal)

    elif args.json: # export to json
        print(exporters.to_json(journal))

    elif args.markdown: # export to json
        print(exporters.to_md(journal))

    elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTO:
        print("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.")

    elif args.encrypt is not False:
        encrypt(journal, filename=args.encrypt)
        # Not encrypting to a separate file: update config!
        if not args.encrypt:
            update_config(original_config, {"encrypt": True, "password": ""}, journal_name)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.decrypt is not False:
        decrypt(journal, filename=args.decrypt)
        # Not decrypting to a separate file: update config!
        if not args.decrypt:
            update_config(original_config, {"encrypt": False, "password": ""}, journal_name)
            install.save_config(original_config, config_path=CONFIG_PATH)

    elif args.delete_last:
        last_entry = journal.entries.pop()
        print("[Deleted Entry:]")
        print(last_entry)
        journal.write()