mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Implement basic sync functionality
Signed-off-by: Aniket Pant <me@aniketpant.com>
This commit is contained in:
parent
99fa0fd4f0
commit
021ff9fb38
3 changed files with 39 additions and 14 deletions
|
@ -2,6 +2,7 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from Entry import Entry
|
from Entry import Entry
|
||||||
|
import exporters
|
||||||
import os
|
import os
|
||||||
import parsedatetime.parsedatetime as pdt
|
import parsedatetime.parsedatetime as pdt
|
||||||
import re
|
import re
|
||||||
|
@ -38,6 +39,7 @@ class Journal(object):
|
||||||
'highlight': True,
|
'highlight': True,
|
||||||
'linewrap': 80,
|
'linewrap': 80,
|
||||||
'folder': os.path.expanduser("~/journal/"),
|
'folder': os.path.expanduser("~/journal/"),
|
||||||
|
'sync_folder': os.path.expanduser("~/journal/"),
|
||||||
}
|
}
|
||||||
self.config.update(kwargs)
|
self.config.update(kwargs)
|
||||||
|
|
||||||
|
@ -273,6 +275,18 @@ class Journal(object):
|
||||||
self.sort()
|
self.sort()
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
def sync(self, arg):
|
||||||
|
if arg == "json":
|
||||||
|
exporters.to_json(self, self.config['sync_folder'] + "journal.json")
|
||||||
|
elif arg == "md":
|
||||||
|
exporters.to_md(self, self.config['sync_folder'] + "journal.md")
|
||||||
|
elif arg == "txt":
|
||||||
|
exporters.to_txt(self, self.config['sync_folder'] + "journal.txt")
|
||||||
|
elif arg == "files":
|
||||||
|
exporters.to_files(self, self.config['sync_folder'] + "*.txt")
|
||||||
|
return "journal synced to " + self.config['sync_folder']
|
||||||
|
|
||||||
|
|
||||||
class DayOne(Journal):
|
class DayOne(Journal):
|
||||||
"""A special Journal handling DayOne files"""
|
"""A special Journal handling DayOne files"""
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|
|
@ -30,6 +30,7 @@ default_config = {
|
||||||
'highlight': True,
|
'highlight': True,
|
||||||
'linewrap': 80,
|
'linewrap': 80,
|
||||||
'folder': os.path.expanduser("~/journal/"),
|
'folder': os.path.expanduser("~/journal/"),
|
||||||
|
'sync_folder': os.path.expanduser("~/journal/"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +67,16 @@ def install_jrnl(config_path='~/.jrnl_config'):
|
||||||
journal_path = raw_input(path_query).strip() or os.path.expanduser('~/journal.txt')
|
journal_path = raw_input(path_query).strip() or os.path.expanduser('~/journal.txt')
|
||||||
default_config['journals']['default'] = os.path.expanduser(journal_path)
|
default_config['journals']['default'] = os.path.expanduser(journal_path)
|
||||||
|
|
||||||
|
# Where to export files?
|
||||||
|
path_query = 'Path to your journal folder (leave blank for ~/journal): '
|
||||||
|
folder_path = raw_input(path_query).strip() or os.path.expanduser('~/journal')
|
||||||
|
default_config['folder'] = os.path.expanduser(folder_path)
|
||||||
|
|
||||||
|
# Where to sync journal?
|
||||||
|
path_query = 'Path to folder which is a git repository (leave blank for ~/journal): '
|
||||||
|
folder_path = raw_input(path_query).strip() or os.path.expanduser('~/journal')
|
||||||
|
default_config['sync_folder'] = os.path.expanduser(folder_path)
|
||||||
|
|
||||||
# Encrypt it?
|
# Encrypt it?
|
||||||
if module_exists("Crypto"):
|
if module_exists("Crypto"):
|
||||||
password = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
|
password = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
|
||||||
|
@ -91,8 +102,3 @@ def install_jrnl(config_path='~/.jrnl_config'):
|
||||||
if password:
|
if password:
|
||||||
config['password'] = password
|
config['password'] = password
|
||||||
return config
|
return config
|
||||||
|
|
||||||
# Where to export files?
|
|
||||||
path_query = 'Path to your journal folder (leave blank for ~/journal): '
|
|
||||||
folder_path = raw_input(path_query).strip() or os.path.expanduser('~/journal')
|
|
||||||
default_config['folder'] = os.path.expanduser(folder_path)
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ def parse_args():
|
||||||
exporting.add_argument('--encrypt', metavar='FILENAME', dest='encrypt', help='Encrypts your existing journal with a new password', nargs='?', default=False, const=None)
|
exporting.add_argument('--encrypt', metavar='FILENAME', dest='encrypt', help='Encrypts your existing journal with a new password', nargs='?', default=False, const=None)
|
||||||
exporting.add_argument('--decrypt', metavar='FILENAME', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=None)
|
exporting.add_argument('--decrypt', metavar='FILENAME', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=None)
|
||||||
exporting.add_argument('--delete-last', dest='delete_last', help='Deletes the last entry from your journal file.', action="store_true")
|
exporting.add_argument('--delete-last', dest='delete_last', help='Deletes the last entry from your journal file.', action="store_true")
|
||||||
|
exporting.add_argument('--sync', metavar='TYPE', dest='sync', help='Syncs your journal to a repository. Works similar to export.', nargs='?', default=False, const=None)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ def guess_mode(args, config):
|
||||||
"""Guesses the mode (compose, read or export) from the given arguments"""
|
"""Guesses the mode (compose, read or export) from the given arguments"""
|
||||||
compose = True
|
compose = True
|
||||||
export = False
|
export = False
|
||||||
if args.decrypt is not False or args.encrypt is not False or args.export is not False or args.tags or args.delete_last:
|
if args.decrypt is not False or args.encrypt is not False or args.export is not False or args.tags or args.delete_last or args.sync is not False:
|
||||||
compose = False
|
compose = False
|
||||||
export = True
|
export = True
|
||||||
elif args.start_date or args.end_date or args.limit or args.strict or args.short:
|
elif args.start_date or args.end_date or args.limit or args.strict or args.short:
|
||||||
|
@ -196,7 +197,8 @@ def cli():
|
||||||
elif args.tags:
|
elif args.tags:
|
||||||
print_tags(journal)
|
print_tags(journal)
|
||||||
|
|
||||||
elif args.export == 'json': # export to json
|
elif args.export is not False:
|
||||||
|
if args.export == 'json': # export to json
|
||||||
print(exporters.to_json(journal, args.output))
|
print(exporters.to_json(journal, args.output))
|
||||||
|
|
||||||
elif args.export == 'markdown' or args.export == 'md': # export to markdown
|
elif args.export == 'markdown' or args.export == 'md': # export to markdown
|
||||||
|
@ -208,6 +210,9 @@ def cli():
|
||||||
elif args.export == 'files': # export to files
|
elif args.export == 'files': # export to files
|
||||||
print(exporters.to_files(journal, args.output))
|
print(exporters.to_files(journal, args.output))
|
||||||
|
|
||||||
|
elif args.sync is not False: # syncs journal to repository
|
||||||
|
print(journal.sync(args.sync))
|
||||||
|
|
||||||
elif (args.encrypt is not False or args.decrypt is not False) and not PYCRYPTO:
|
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.")
|
print("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue