get version from module, basic style a bit simpler
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
__version__ = "2021-08-21.0"
|
||||
|
||||
|
||||
def get_version():
|
||||
return __version__
|
||||
|
||||
|
||||
def main():
|
||||
from mirva.mirva import Mirva
|
||||
|
||||
Mirva()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
@@ -7,6 +5,7 @@ import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from argparse import ArgumentParser
|
||||
from mirva import get_version
|
||||
|
||||
|
||||
class Mirva:
|
||||
@@ -16,14 +15,14 @@ class Mirva:
|
||||
os.path.dirname(os.path.abspath(__file__)), "resources"
|
||||
)
|
||||
self.resource_dir = ".mirva"
|
||||
self.config_file = os.path.join(self.resource_dir, "config")
|
||||
self.config_file = os.path.join(self.resource_dir, "config.cfg")
|
||||
self.get_options()
|
||||
os.chdir(self.options.folder)
|
||||
self.write_resources()
|
||||
self.file_list = self.get_files()
|
||||
if self.options.config or not os.path.exists(self.config_file):
|
||||
self.create_config()
|
||||
print("Exiting. Check config.")
|
||||
print("Config created: Exiting without gallery creation. Check config first.")
|
||||
return
|
||||
self.create_config()
|
||||
self.get_config()
|
||||
@@ -42,17 +41,23 @@ class Mirva:
|
||||
"title": "",
|
||||
"sub_title": "",
|
||||
"intro": "",
|
||||
"image_size": 850
|
||||
"image_size": 850,
|
||||
}
|
||||
config_changed = True
|
||||
|
||||
for f in self.file_list:
|
||||
if not f in config:
|
||||
config[f] = {"title": f, "description": ""}
|
||||
title, _ = os.path.splitext(f)
|
||||
title = title.replace("_", " ")
|
||||
config[f] = {"title": title, "description": ""}
|
||||
config_changed = True
|
||||
|
||||
if config_changed:
|
||||
print("Modified config: {}".format(os.path.join(self.options.folder,self.config_file)))
|
||||
print(
|
||||
"Modified config: {}".format(
|
||||
os.path.join(self.options.folder, self.config_file)
|
||||
)
|
||||
)
|
||||
with open(self.config_file, "wt") as fp:
|
||||
config.write(fp)
|
||||
|
||||
@@ -82,16 +87,27 @@ class Mirva:
|
||||
return files
|
||||
|
||||
def get_options(self):
|
||||
parser = ArgumentParser()
|
||||
parser = ArgumentParser(
|
||||
prog="mirva",
|
||||
epilog='Configuration note: item "image_size = [integer]" is the '
|
||||
+ "middle sized image max width/height in pixels. It also accepts a special "
|
||||
+ 'value "link" to make symbolic links.',
|
||||
)
|
||||
# parser.add_argument("-v", default=False, action="store_true")
|
||||
parser.add_argument(
|
||||
"--config", default=False, action="store_true", help="Write config and exit"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--force", default=False, action="store_true", help="Force regeneration of middle sized images"
|
||||
"--force",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="Force regeneration of middle sized images",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version",
|
||||
action="version",
|
||||
version="%(prog)s {version}".format(version=get_version()),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"folder",
|
||||
type=str,
|
||||
@@ -117,8 +133,7 @@ Released : 20110306
|
||||
-->
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta name="keywords" content="" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="generator" content="Mirva" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<link rel="shortcut icon" href="{resource}/mirva.ico"/>
|
||||
@@ -132,6 +147,10 @@ r(function(){{
|
||||
function create_nav() {{
|
||||
let navis = document.getElementsByClassName("navigation");
|
||||
for (let i = 0; i<navis.length; i++) {{
|
||||
if (i==navis.length-1) {{
|
||||
navis[i].appendChild(create_button("up", navis[0]));
|
||||
continue;
|
||||
}}
|
||||
if (navis[i-1]) {{
|
||||
navis[i].appendChild(create_button("up", navis[i-1]));
|
||||
}} else {{
|
||||
@@ -208,8 +227,22 @@ function create_button(direction, to) {{
|
||||
image=image, title=title, content=content
|
||||
)
|
||||
|
||||
|
||||
def is_created_with_mirva(self):
|
||||
|
||||
with open("index.html", "rt") as fp:
|
||||
for line in fp.readlines():
|
||||
if line.strip() == '<meta name="generator" content="Mirva" />':
|
||||
return True
|
||||
return False
|
||||
|
||||
def write_index(self):
|
||||
|
||||
if os.path.exists("index.html"):
|
||||
if not self.is_created_with_mirva():
|
||||
print("index.html exists, and it's not written with Mirva. Not overwriting.")
|
||||
sys.exit(1)
|
||||
|
||||
with open("index.html", "wt") as fp:
|
||||
fp.write(
|
||||
self.get_index(
|
||||
@@ -227,7 +260,13 @@ function create_button(direction, to) {{
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for f in ("style.css", "arrow_up.png", "arrow_down.png", "banner.jpg", "mirva.ico"):
|
||||
for f in (
|
||||
"style.css",
|
||||
"arrow_up.png",
|
||||
"arrow_down.png",
|
||||
"banner.jpg",
|
||||
"mirva.ico",
|
||||
):
|
||||
if os.path.exists(os.path.join(self.resource_dir, f)):
|
||||
continue
|
||||
shutil.copy(
|
||||
@@ -246,7 +285,6 @@ function create_button(direction, to) {{
|
||||
if link:
|
||||
r = 0
|
||||
|
||||
|
||||
force = self.options.force
|
||||
for f in self.file_list:
|
||||
res = "{:d}x{:d}>".format(int(r), int(r))
|
||||
@@ -260,10 +298,7 @@ function create_button(direction, to) {{
|
||||
if not os.path.exists(outfile):
|
||||
if link:
|
||||
|
||||
os.symlink(
|
||||
"../{}".format(f),
|
||||
outfile
|
||||
)
|
||||
os.symlink("../{}".format(f), outfile)
|
||||
continue
|
||||
|
||||
convargs = [
|
||||
@@ -283,6 +318,3 @@ function create_button(direction, to) {{
|
||||
sys.stdout.write(".")
|
||||
sys.stdout.flush()
|
||||
subprocess.call(convargs)
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 167 KiB After Width: | Height: | Size: 5.4 KiB |
@@ -199,7 +199,8 @@ a:hover {
|
||||
}
|
||||
@media only screen and (max-width: 800px) {
|
||||
.post_image {
|
||||
max-width: 100vw;
|
||||
max-height: calc(100vh - 2px);
|
||||
max-width: calc(100vw - 2px);
|
||||
}
|
||||
}
|
||||
/* Footer */
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
from mirva.mirva import Mirva
|
||||
|
||||
if __name__ == '__main__':
|
||||
Mirva()
|
||||
@@ -1,2 +1,10 @@
|
||||
[metadata]
|
||||
description-file = README.md
|
||||
version = attr: mirva.__version__
|
||||
license = MIT
|
||||
description = A tool to create a web gallery from a folder of images.
|
||||
author = Ville Rantanen
|
||||
author_email = ville.q.rantanen@gmail.com
|
||||
url = https://bitbucket.org/MoonQ/mirva
|
||||
download_url = https://bitbucket.org/MoonQ/mirva/get/master.zip
|
||||
keywords = album, generator, javascript
|
||||
|
||||
22
setup.py
22
setup.py
@@ -1,18 +1,14 @@
|
||||
from distutils.core import setup
|
||||
|
||||
setup(
|
||||
name = 'mirva',
|
||||
packages = ['mirva'],
|
||||
scripts = ['scripts/mirva',
|
||||
],
|
||||
package_data={'':['resources/*']},
|
||||
name="mirva",
|
||||
packages=["mirva"],
|
||||
package_data={"": ["resources/*"]},
|
||||
include_package_data=True,
|
||||
version = '20210820',
|
||||
description = 'A tool to create a web gallery from a folder of images.',
|
||||
author = 'Ville Rantanen',
|
||||
author_email = 'ville.q.rantanen@gmail.com',
|
||||
url = 'https://bitbucket.org/MoonQ/mirva',
|
||||
download_url = 'https://bitbucket.org/MoonQ/mirva/get/master.zip',
|
||||
keywords = ['album', 'generator', 'javascript'],
|
||||
classifiers=[],
|
||||
license = 'MIT',
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"mirva=mirva:main",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user