mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
saving forces blanks to be appended
This commit is contained in:
parent
9c18fdc9b4
commit
acb7fa2ed4
1 changed files with 10 additions and 3 deletions
13
jrnl.py
13
jrnl.py
|
@ -14,6 +14,7 @@ import sys
|
||||||
import readline, glob
|
import readline, glob
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
import getpass
|
import getpass
|
||||||
|
import mimetypes
|
||||||
|
|
||||||
default_config = {
|
default_config = {
|
||||||
'journal': os.path.expanduser("~/journal.txt"),
|
'journal': os.path.expanduser("~/journal.txt"),
|
||||||
|
@ -76,8 +77,10 @@ class Journal:
|
||||||
self.entries = self.open()
|
self.entries = self.open()
|
||||||
self.sort()
|
self.sort()
|
||||||
|
|
||||||
def _block_tail(self, s, b=16):
|
def _block_tail(self, s, b=16, force=False):
|
||||||
"""Appends spaces to a string until length is a multiple of b"""
|
"""Appends spaces to a string until length is a multiple of b"""
|
||||||
|
if force and len(s) % 16 == 0:
|
||||||
|
return s + " "*16
|
||||||
return s + " "*(b - len(s) % b)
|
return s + " "*(b - len(s) % b)
|
||||||
|
|
||||||
def open(self, filename=None):
|
def open(self, filename=None):
|
||||||
|
@ -100,6 +103,10 @@ class Journal:
|
||||||
key = self._block_tail(key)
|
key = self._block_tail(key)
|
||||||
self.crypto = AES.new(key, AES.MODE_ECB)
|
self.crypto = AES.new(key, AES.MODE_ECB)
|
||||||
journal_plain = self.crypto.decrypt(journal_encrypted)
|
journal_plain = self.crypto.decrypt(journal_encrypted)
|
||||||
|
|
||||||
|
print len(journal_plain)
|
||||||
|
print journal_plain[-16:]
|
||||||
|
print 'xxxxxxxxxx'
|
||||||
else:
|
else:
|
||||||
journal_plain = f.read()
|
journal_plain = f.read()
|
||||||
|
|
||||||
|
@ -141,7 +148,7 @@ class Journal:
|
||||||
journal_plain = os.linesep.join([str(e) for e in self.entries])
|
journal_plain = os.linesep.join([str(e) for e in self.entries])
|
||||||
with open(filename, 'w') as journal_file:
|
with open(filename, 'w') as journal_file:
|
||||||
if self.crypto:
|
if self.crypto:
|
||||||
journal_padded = self._block_tail(journal_plain)
|
journal_padded = self._block_tail(journal_plain, force=True)
|
||||||
journal_file.write(self.crypto.encrypt(journal_padded))
|
journal_file.write(self.crypto.encrypt(journal_padded))
|
||||||
else:
|
else:
|
||||||
journal_file.write(journal_plain)
|
journal_file.write(journal_plain)
|
||||||
|
@ -238,7 +245,7 @@ if __name__ == "__main__":
|
||||||
default_config['journal'] = os.path.expanduser(journal_path)
|
default_config['journal'] = os.path.expanduser(journal_path)
|
||||||
open(default_config['journal'], 'a').close() # Touch to make sure it's there
|
open(default_config['journal'], 'a').close() # Touch to make sure it's there
|
||||||
with open(config_path, 'w') as f:
|
with open(config_path, 'w') as f:
|
||||||
json.dump(default_config, f)
|
json.dump(default_config, f, indent=2)
|
||||||
with open(config_path) as f:
|
with open(config_path) as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue