Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 29, 2019
1 parent 8c14153 commit 7907da7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions scan_to_paperless/__init__.py
Expand Up @@ -14,6 +14,6 @@

def get_config():
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, encoding='utf-8') as f:
return yaml.safe_load(f.read())
with open(CONFIG_PATH, encoding='utf-8') as config_file:
return yaml.safe_load(config_file.read())
return {}
57 changes: 27 additions & 30 deletions scan_to_paperless/scan.py
Expand Up @@ -12,35 +12,40 @@
import re
import sqlite3
import subprocess
import sys
import time
import numpy as np

import argcomplete
from argcomplete.completers import ChoicesCompleter
import yaml
from argcomplete.completers import ChoicesCompleter
from skimage import io
from skimage.transform import rotate
from scan_to_paperless import CONFIG_FOLDER, get_config

from scan_to_paperless import CONFIG_FOLDER, CONFIG_PATH, get_config

CACHE_FILENAME = 'scan-to-paperless-cache.json'
CACHE_PATH = os.path.join(CONFIG_FOLDER, CACHE_FILENAME)


def call(cmd, cmd2=None, **kwargs):
del cmd2
print(' '.join(cmd) if isinstance(cmd, list) else cmd)
try:
subprocess.check_call(cmd, **kwargs)
except subprocess.CalledProcessError as e:
print(e)
exit(1)
except subprocess.CalledProcessError as exeception:
print(exeception)
sys.exit(1)


def output(cmd, cmd2=None, **kwargs):
del cmd2
print(' '.join(cmd) if isinstance(cmd, list) else cmd)
try:
return subprocess.check_output(cmd, **kwargs)
except subprocess.CalledProcessError as e:
print(e)
exit(1)
except subprocess.CalledProcessError as exeception:
print(exeception)
sys.exit(1)


def main():
Expand All @@ -53,8 +58,8 @@ def main():
}
update_cache = True
if os.path.exists(CACHE_PATH):
with open(CACHE_PATH, encoding='utf-8') as f:
cache = json.loads(f.read())
with open(CACHE_PATH, encoding='utf-8') as cache_file:
cache = json.loads(cache_file.read())
if cache['time'] > time.time() - 3600:
update_cache = False

Expand All @@ -76,14 +81,6 @@ def main():
cache['time'] = time.time()
with open(config['paperless_dump']) as dumpdata:
dump = json.loads(dumpdata.read())
{
'model': 'contenttypes.contenttype',
'pk': 1,
'fields': {
'app_label': 'auth',
'model': 'permission'
}
}

for element in dump:
if element['model'] == 'documents.correspondent':
Expand All @@ -96,8 +93,8 @@ def main():
scan --set-settings paperless_db <the_path>, or
scan --set-settings paperless_dump <the_path>.''')

with open(CACHE_PATH, 'w', encoding='utf-8') as f:
f.write(json.dumps(cache))
with open(CACHE_PATH, 'w', encoding='utf-8') as config_file:
config_file.write(json.dumps(cache))

parser = argparse.ArgumentParser()

Expand Down Expand Up @@ -169,21 +166,21 @@ def add_argument(name, choices=None, **kwargs):
args = parser.parse_args()

dirty = False
for conf in args.set_config:
for conf in args.set_cofig:
config[conf[0]] = conf[1]
dirty = True
if dirty:
with open(CONFIG_PATH, 'w', encoding='utf-8') as f:
f.write(yaml.safe_dump(config, default_flow_style=False))
with open(CONFIG_PATH, 'w', encoding='utf-8') as config_file:
config_file.write(yaml.safe_dump(config, default_flow_style=False))

if len(args.title) == 0:
exit(0)
sys.exit(0)

if 'scan_folder' not in config:
print('''The scan folder isn't set, use:
scan --set-settings scan_folder <a_folder>
This should be shared with the process container in 'source'.''')
exit(1)
sys.exit(1)

full_name = ' '.join(args.title)
if args.correspondent is not None:
Expand All @@ -196,7 +193,7 @@ def add_argument(name, choices=None, **kwargs):
)
if '/' in full_name:
print("The name can't contans some '/' (from correspondent, tags or title).")
exit(1)
sys.exit(1)

root_folder = os.path.join(
os.path.expanduser(config['scan_folder']),
Expand Down Expand Up @@ -242,7 +239,7 @@ def add_argument(name, choices=None, **kwargs):
images = sorted(images, key=lambda e: int(regex.match(e).group(1)))
args_ = {}
args_.update(config.get('default_args', {}))
args_.update(dict(args._get_kwargs()))
args_.update(dict([arg.split("=") for arg in args]))
config = {
'images': images,
'full_name': full_name,
Expand All @@ -252,9 +249,9 @@ def add_argument(name, choices=None, **kwargs):
with open(os.path.join(os.path.dirname(root_folder), 'config.yaml'), 'w') as config_file:
config_file.write(yaml.safe_dump(config, default_flow_style=False))

except subprocess.CalledProcessError as e:
print(e)
exit(1)
except subprocess.CalledProcessError as exeception:
print(exeception)
sys.exit(1)

print(root_folder)
subprocess.call([config.get('viewer', 'eog'), root_folder])
1 change: 0 additions & 1 deletion scan_to_paperless/scan_process_status.py
Expand Up @@ -10,7 +10,6 @@

def main():
config = get_config()
scan_folder:
for folder in glob.glob(os.path.join(os.path.expanduser(config['scan_folder']), '*')):
print(re.sub(r'.', '-', folder))
print(folder)
Expand Down

0 comments on commit 7907da7

Please sign in to comment.