Пример #1
0
def make_image_cache(img_cache):
    """
    Initiates the image cache if it does not exist
    """
    log.info('Initiating the image cache at {0}'.format(img_cache))
    if not os.path.isdir(img_cache):
        utils.mkdir_p(img_cache)
        utils.mkdir_p(os.path.join(img_cache, '10.1371'))
        utils.mkdir_p(os.path.join(img_cache, '10.3389'))
Пример #2
0
def make_image_cache(img_cache):
    """
    Initiates the image cache if it does not exist
    """
    log.info('Initiating the image cache at {0}'.format(img_cache))
    if not os.path.isdir(img_cache):
        utils.mkdir_p(img_cache)
        utils.mkdir_p(os.path.join(img_cache, '10.1371'))
        utils.mkdir_p(os.path.join(img_cache, '10.3389'))
Пример #3
0
def inner_main(args):
    """
    The inner control loops for user interaction during quickstart
    configuration.
    """

    # Make the cache directory
    mkdir_p(CACHE_LOCATION)

    default_config = {
        "now": time.asctime(),
        "oae-version": OAE_VERSION,
        "cache-location": unix_path_coercion(CACHE_LOCATION),
        "input-relative-images": "images",
        "use-input-relative-images": "y",
        "image-cache": os.path.join(CACHE_LOCATION, "img_cache"),
        "use-image-cache": "n",
        "use-image-fetching": "y",
        "default-output": ".",
        "input-relative-css": ".",
        "epubcheck": os.path.join(CACHE_LOCATION, "epubcheck-3.0", "epubcheck-3.0.jar"),
    }

    if args[-1] == "-d":  # Use all default options flag
        # Pass through the validation/modification steps
        default_config["input-relative-images"] = list_opts(default_config["input-relative-images"])
        default_config["use-input-relative-images"] = boolean(default_config["use-input-relative-images"])
        default_config["image-cache"] = absolute_path(default_config["image-cache"])
        default_config["use-image-cache"] = boolean(default_config["use-image-cache"])
        default_config["use-image-fetching"] = boolean(default_config["use-image-fetching"])
        default_config["default-output"] = nonempty(default_config["default-output"])
        default_config["input-relative-css"] = nonempty(default_config["input-relative-css"])
        default_config["epubcheck"] = absolute_path(default_config["epubcheck"])
        config = config_formatter(CONFIG_TEXT, default_config)
        with open(os.path.join(CACHE_LOCATION, "config.py"), "wb") as conf_out:
            conf_out.write(bytes(config, "UTF-8"))
        print("The config file has been written to {0}".format(os.path.join(CACHE_LOCATION, "config.py")))
        return

    config_dict = {
        "now": time.asctime(),
        "oae-version": OAE_VERSION,
        "cache-location": unix_path_coercion(CACHE_LOCATION),
    }

    print("\nWelcome to the quickstart configuration for OpenAccess_EPUB")
    print(
        """
Please enter values for the following settings. To accept the default value
for the settings, shown in brackets, just push Enter.

-------------------------------------------------------------------------------\
"""
    )
    print(
        """
OpenAccess_EPUB defines a default cache location for the storage of various
data (and the global config.py file), this location is:\n\n{0}
""".format(
            CACHE_LOCATION
        )
    )

    input("Press Enter to start...")

    # Image Configuration
    print(
        """
 -- Configure Image Behavior --

When OpenAccess_EPUB is executed using the oaepub script, it can find the
images for the input articles according to the following strategies (in order
of preference):

 Input-Relative: a path relative to the input file
 Cached Images: locate the images in a cache
 Fetched Online: attempts to download from the Internet (may fail)

We'll configure some values for each of these, and you\'ll also have the option
to turn them off."""
    )
    # Input-relative image details
    print(
        """
Where should OpenAccess_EPUB look for images relative to the input file?
Multiple path values may be specified if separated by commas."""
    )
    user_prompt(
        config_dict,
        "input-relative-images",
        "Input-relative images?:",
        default=default_config["input-relative-images"],
        validator=list_opts,
    )
    print(
        """
Should OpenAccess_EPUB look for images relative to the input file by default?\
"""
    )
    user_prompt(
        config_dict,
        "use-input-relative-images",
        "Use input-relative images?: (Y/n)",
        default=default_config["use-input-relative-images"],
        validator=boolean,
    )
    # Image cache details
    print(
        """
Where should OpenAccess_EPUB place the image cache?"""
    )
    user_prompt(
        config_dict, "image-cache", "Image cache?:", default=default_config["image-cache"], validator=absolute_path
    )
    print(
        """
Should OpenAccess_EPUB use the image cache by default? This feature is intended
for developers and testers without local access to the image files and will
consume extra disk space for storage."""
    )
    user_prompt(
        config_dict,
        "use-image-cache",
        "Use image cache?: (y/N)",
        default=default_config["use-image-cache"],
        validator=boolean,
    )
    # Image fetching online details
    print(
        """
Should OpenAccess_EPUB attempt to download the images from the Internet? This
is not supported for all publishers and not 100% guaranteed to succeed, you may
need to download them manually if this does not work."""
    )
    user_prompt(
        config_dict,
        "use-image-fetching",
        "Attempt image download?: (Y/n)",
        default=default_config["use-image-fetching"],
        validator=boolean,
    )
    # Output configuration
    print(
        """
 -- Configure Output Behavior --

OpenAccess_EPUB produces ePub and log files as output. The following options
will determine what is done with these.

Where should OpenAccess_EPUB place the output ePub and log files? If you supply
a relative path, the output path will be relative to the input; if you supply
an absolute path, the output will always be placed there. The default behavior
is to place them in the same directory as the input."""
    )
    user_prompt(
        config_dict, "default-output", "Output path?:", default=default_config["default-output"], validator=nonempty
    )
    print(
        """
 -- Configure CSS Behavior --

ePub files use CSS for improved styling, and ePub-readers must support a basic
subset of CSS functions. OpenAccess_EPUB provides a default CSS file, but a
manual one may be supplied, relative to the input. Please define an
appropriate input-relative path."""
    )
    user_prompt(
        config_dict,
        "input-relative-css",
        "Input-relative CSS path?:",
        default=default_config["input-relative-css"],
        validator=nonempty,
    )
    print(
        """
 -- Configure EpubCheck --

EpubCheck is a program written and maintained by the IDPF as a tool to validate
ePub. In order to use it, your system must have Java installed and it is
recommended to use the latest version. The website for the program is here:

http://code.google.com/p/epubcheck/

Once you have downloaded the zip file for the program, unzip the archive and
write a path to the .jar file here."""
    )
    user_prompt(
        config_dict,
        "epubcheck",
        "Absolute path to epubcheck?:",
        default=default_config["epubcheck"],
        validator=absolute_path,
    )
    # Write the config.py file
    config = config_formatter(CONFIG_TEXT, config_dict)
    with open(os.path.join(CACHE_LOCATION, "config.py"), "wb") as conf_out:
        conf_out.write(bytes(config, "UTF-8"))
    print(
        """
Done configuring OpenAccess_EPUB!"""
    )