Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Import directory is variable now
  • Loading branch information
kthoden committed Feb 27, 2020
1 parent 5521490 commit a93a88f
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion eoapublications/management/commands/publicationimport.py
Expand Up @@ -16,6 +16,47 @@
class Command(BaseCommand):
help = "Import a publication into the Django database."

def add_arguments(self, parser):
parser.add_argument(
'inputDir',
default='import',
nargs='?',
metavar='INPUT_DIR',
help='import publication from INPUT_DIR. default: %(default)s'
)

def input_dir_sanitycheck(self, inputDir):
from os.path import exists, join
for f in \
[ inputDir
, join( inputDir, "publication.cfg")
, join( inputDir, "Django.xml")
, join( inputDir, "Cover.jpg")
, join( inputDir, "images")
, join( inputDir, "images/embedded") \
] \
:
if not exists( f ):
raise( FileNotFoundError(f) )

def dest_dir_sanitycheck(self, destDir):
from os.path import exists, join
if( exists( destDir ) ):
raise( FileExistsError( destDir ) )

def dbg_print( self, x, level=1, **options):
verbosity = options['verbosity'] if ('verbosity' in options.keys()) else 0
if level <= verbosity:
print( x )

def dest_media_dir( self, inputDir ):
from os.path import join
config = configparser.ConfigParser(); config.read( join(inputDir, 'publication.cfg') )
technical = config['Technical']
mediaDestRel = join( technical['Serie'].lower() , technical['Number'] )
return join( settings.MEDIA_ROOT, mediaDestRel )


def resize_image(self, source_image, dest_image, max_size, dimension):
"""Resize an image, preserve ratio.
Expand Down Expand Up @@ -59,6 +100,7 @@ def process_as_string(self,xmlElement):
return strResult
# def process_as_string ends here


def process_index_entries(self, xmlIndex, xmlElement, xmlChapter, Newelement, Newpublication, index_type):
"""Construct the popups for index entries next to paragraphs."""

Expand Down Expand Up @@ -223,9 +265,16 @@ def progress(self, count, total, status=''):

def handle(self, **options):
"""The main bit."""
from os import getcwd, mkdir, makedirs
from os.path import exists, join

inputDir = join( getcwd(), options['inputDir'] )
self.input_dir_sanitycheck( inputDir )

strDir = inputDir

# Get current directory, and append /import
strDir = os.getcwd() + '/import'
# strDir = os.getcwd() + '/import'
# Read .cfg-File
cfgPublication = configparser.ConfigParser()
cfgPublication.read(strDir + '/publication.cfg')
Expand Down

0 comments on commit a93a88f

Please sign in to comment.