mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
name copied file by random string
move data folder creation to init
This commit is contained in:
parent
cee238b7a5
commit
01131ce5c8
2 changed files with 12 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from Entry import Entry
|
from Entry import Entry
|
||||||
import os
|
import os, random, string
|
||||||
import parsedatetime.parsedatetime as pdt
|
import parsedatetime.parsedatetime as pdt
|
||||||
import parsedatetime.parsedatetime_consts as pdc
|
import parsedatetime.parsedatetime_consts as pdc
|
||||||
import re
|
import re
|
||||||
|
@ -29,7 +29,12 @@ class Journal:
|
||||||
def __init__(self, config, **kwargs):
|
def __init__(self, config, **kwargs):
|
||||||
config.update(kwargs)
|
config.update(kwargs)
|
||||||
self.config = config
|
self.config = config
|
||||||
|
# TODO: comment regex
|
||||||
self.path_search = re.compile('[\[\(]?(([A-Z]:|/)\S*?\.(tif|tiff|jpg|jpeg|gif|png))[\[\)]?')
|
self.path_search = re.compile('[\[\(]?(([A-Z]:|/)\S*?\.(tif|tiff|jpg|jpeg|gif|png))[\[\)]?')
|
||||||
|
self.data_path = os.path.splitext(self.config['journal'])[0] + '_data'
|
||||||
|
# TODO: maybe move to setup in jrnl.py
|
||||||
|
if not os.path.exists(self.data_path):
|
||||||
|
os.mkdir(self.data_path)
|
||||||
|
|
||||||
# Set up date parser
|
# Set up date parser
|
||||||
consts = pdc.Constants()
|
consts = pdc.Constants()
|
||||||
|
@ -73,6 +78,9 @@ class Journal:
|
||||||
plain += " " * 16
|
plain += " " * 16
|
||||||
return iv + crypto.encrypt(plain)
|
return iv + crypto.encrypt(plain)
|
||||||
|
|
||||||
|
def _random_string(self, length=20):
|
||||||
|
return ''.join(random.choice(string.letters+string.digits) for _ in range(length))
|
||||||
|
|
||||||
def make_key(self, prompt="Password: "):
|
def make_key(self, prompt="Password: "):
|
||||||
"""Creates an encryption key from the default password or prompts for a new password."""
|
"""Creates an encryption key from the default password or prompts for a new password."""
|
||||||
password = self.config['password'] or getpass.getpass(prompt)
|
password = self.config['password'] or getpass.getpass(prompt)
|
||||||
|
@ -244,12 +252,9 @@ class Journal:
|
||||||
if res and len(res.groups()) == 2 and os.path.exists(word.strip('()[]')):
|
if res and len(res.groups()) == 2 and os.path.exists(word.strip('()[]')):
|
||||||
word = word.strip('()[]')
|
word = word.strip('()[]')
|
||||||
print word
|
print word
|
||||||
save_path = os.path.splitext(self.config['journal'])[0] + '_data'
|
ext = os.path.splitext(os.path.basename(word))[1]
|
||||||
if not os.path.exists(save_path):
|
random_name = 'img_' + self._random_string() + ext
|
||||||
os.mkdir(save_path)
|
shutil.copyfile(word, os.path.join(self.data_path, random_name))
|
||||||
new_path = os.path.join(save_path, os.path.basename(word))
|
|
||||||
# TODO: replace name by hash
|
|
||||||
shutil.copyfile(word, new_path)
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def new_entry(self, raw, date=None):
|
def new_entry(self, raw, date=None):
|
||||||
|
|
BIN
tests/golden.jpg
Normal file
BIN
tests/golden.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 100 KiB |
Loading…
Add table
Reference in a new issue