-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
168 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .settings import ( | ||
DefaultSettings, | ||
MgLibSettings | ||
) | ||
|
||
settings = MgLibSettings( | ||
DefaultSettings() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
# file utility used to find out mime type of a file | ||
BINARY_FILE = "/usr/bin/file" | ||
|
||
# Provided by ImageMagick package. | ||
# Used for resizing images. | ||
BINARY_CONVERT = "/usr/bin/convert" | ||
|
||
# Provided by Poppler Utils. | ||
# Used to extract images from PDF file. | ||
BINARY_PDFTOPPM = "/usr/bin/pdftoppm" | ||
|
||
# Provided by Poppler Utils. | ||
# used to get page count in PDF file | ||
BINARY_PDFINFO = "/usr/bin/pdfinfo" | ||
|
||
# Provided by ImageMagick package. | ||
# Used to get number of pages in TIFF file. | ||
BINARY_IDENTIFY = "/usr/bin/identify" | ||
|
||
# Provided by tesseract package. | ||
# Used to extract text from images/PDF files. | ||
BINARY_OCR = "/usr/bin/tesseract" | ||
|
||
# Provided by pdftk package | ||
# Used to reorder, cut/paste, delete pages withing PDF document | ||
BINARY_PDFTK = "/usr/bin/pdftk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import importlib | ||
|
||
try: | ||
from django.conf import settings as django_settings | ||
except ImportError: | ||
# Operating outside django, use own settings module | ||
django_settings = None | ||
|
||
|
||
class DefaultSettings: | ||
|
||
def __init__( | ||
self, | ||
settings_module="mglib.conf.default_settings" | ||
): | ||
self.SETTINGS_MODULE = settings_module | ||
|
||
mod = importlib.import_module( | ||
self.SETTINGS_MODULE | ||
) | ||
|
||
for setting in dir(mod): | ||
if setting.isupper(): | ||
setting_value = getattr(mod, setting) | ||
setattr(self, setting, setting_value) | ||
|
||
def configure(self, **options): | ||
for name, value in options.items(): | ||
setattr(self, name, value) | ||
|
||
|
||
class MgLibSettings: | ||
|
||
def __init__( | ||
self, default_settings | ||
): | ||
self.default_settings = default_settings | ||
|
||
def __getattr__(self, name): | ||
# When operating withing django, | ||
# get configuration from django settings | ||
if not name.isupper(): | ||
raise AttributeError | ||
|
||
if django_settings: | ||
val = getattr(django_settings, name) | ||
return val | ||
|
||
val = getattr(self.default_settings, name) | ||
return val | ||
|
||
def configure(self, **options): | ||
self.default_settings.configure( | ||
**options | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
from pathlib import Path | ||
import unittest | ||
|
||
from mglib.conf.settings import ( | ||
MgLibSettings, | ||
DefaultSettings | ||
) | ||
|
||
DATA_DIR = os.path.join( | ||
Path(__file__).parent, | ||
'data' | ||
) | ||
|
||
|
||
class TestMgLibSettings(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.settings = MgLibSettings(DefaultSettings()) | ||
|
||
def test_settings_outside_django_should_work(self): | ||
""" | ||
Without django there should be default values | ||
for settings | ||
""" | ||
# check default value for pdfinfo | ||
self.assertEqual( | ||
"/usr/bin/pdfinfo", | ||
self.settings.BINARY_PDFINFO | ||
) | ||
|
||
def test_settings_are_configurable(self): | ||
""" | ||
User should be able to reconfigure mglibsettings | ||
on the go (i.e. change default values). | ||
""" | ||
# check default value for pdfinfo | ||
self.settings.configure( | ||
BINARY_PDFINFO="/usr/bin/xyz" | ||
) | ||
self.assertEqual( | ||
"/usr/bin/xyz", | ||
self.settings.BINARY_PDFINFO | ||
) | ||
|