get version from module, basic style a bit simpler

This commit is contained in:
Ville Rantanen
2021-08-21 11:19:08 +03:00
parent b606b53a48
commit b4e77c3584
9 changed files with 188 additions and 146 deletions

View File

@@ -0,0 +1,11 @@
__version__ = "2021-08-21.0"
def get_version():
return __version__
def main():
from mirva.mirva import Mirva
Mirva()

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
import configparser import configparser
import os import os
import sys import sys
@@ -7,6 +5,7 @@ import re
import shutil import shutil
import subprocess import subprocess
from argparse import ArgumentParser from argparse import ArgumentParser
from mirva import get_version
class Mirva: class Mirva:
@@ -16,14 +15,14 @@ class Mirva:
os.path.dirname(os.path.abspath(__file__)), "resources" os.path.dirname(os.path.abspath(__file__)), "resources"
) )
self.resource_dir = ".mirva" 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() self.get_options()
os.chdir(self.options.folder) os.chdir(self.options.folder)
self.write_resources() self.write_resources()
self.file_list = self.get_files() self.file_list = self.get_files()
if self.options.config or not os.path.exists(self.config_file): if self.options.config or not os.path.exists(self.config_file):
self.create_config() self.create_config()
print("Exiting. Check config.") print("Config created: Exiting without gallery creation. Check config first.")
return return
self.create_config() self.create_config()
self.get_config() self.get_config()
@@ -42,17 +41,23 @@ class Mirva:
"title": "", "title": "",
"sub_title": "", "sub_title": "",
"intro": "", "intro": "",
"image_size": 850 "image_size": 850,
} }
config_changed = True config_changed = True
for f in self.file_list: for f in self.file_list:
if not f in config: 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 config_changed = True
if config_changed: 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: with open(self.config_file, "wt") as fp:
config.write(fp) config.write(fp)
@@ -82,16 +87,27 @@ class Mirva:
return files return files
def get_options(self): def get_options(self):
parser = ArgumentParser() parser = ArgumentParser(
#parser.add_argument("-v", default=False, action="store_true") 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( parser.add_argument(
"--config", default=False, action="store_true", help="Write config and exit" "--config", default=False, action="store_true", help="Write config and exit"
) )
parser.add_argument( 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( parser.add_argument(
"folder", "folder",
type=str, type=str,
@@ -117,8 +133,7 @@ Released : 20110306
--> -->
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta name="keywords" content="" /> <meta name="generator" content="Mirva" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="{resource}/mirva.ico"/> <link rel="shortcut icon" href="{resource}/mirva.ico"/>
@@ -132,6 +147,10 @@ r(function(){{
function create_nav() {{ function create_nav() {{
let navis = document.getElementsByClassName("navigation"); let navis = document.getElementsByClassName("navigation");
for (let i = 0; i<navis.length; i++) {{ 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]) {{ if (navis[i-1]) {{
navis[i].appendChild(create_button("up", navis[i-1])); navis[i].appendChild(create_button("up", navis[i-1]));
}} else {{ }} else {{
@@ -160,31 +179,31 @@ function create_button(direction, to) {{
</head> </head>
<body> <body>
<div id="wrapper"> <div id="wrapper">
<div id="header"> <div id="header">
<div id="logo"> <div id="logo">
<h1 id="page_title">{page_title}</h1> <h1 id="page_title">{page_title}</h1>
<p>{sub_title}</a></p> <p>{sub_title}</a></p>
</div> </div>
</div> </div>
<!-- end #header --> <!-- end #header -->
<div id="page"> <div id="page">
<div id="page-bgtop"> <div id="page-bgtop">
<div id="page-bgbtm"> <div id="page-bgbtm">
<div id="content"> <div id="content">
<div class="post"> <div class="post">
<div class="entry"> <div class="entry">
{intro} {intro}
</div> </div>
</div> </div>
{posts} {posts}
<div style="clear: both;">&nbsp;</div> <div style="clear: both;">&nbsp;</div>
</div> </div>
<!-- end #content --> <!-- end #content -->
<div style="clear: both;">&nbsp;</div> <div style="clear: both;">&nbsp;</div>
</div> </div>
</div> </div>
<!-- end #page --> <!-- end #page -->
</div> </div>
</body> </body>
</html>""".format( </html>""".format(
@@ -208,8 +227,22 @@ function create_button(direction, to) {{
image=image, title=title, content=content 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): 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: with open("index.html", "wt") as fp:
fp.write( fp.write(
self.get_index( self.get_index(
@@ -227,7 +260,13 @@ function create_button(direction, to) {{
except Exception: except Exception:
pass 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)): if os.path.exists(os.path.join(self.resource_dir, f)):
continue continue
shutil.copy( shutil.copy(
@@ -246,7 +285,6 @@ function create_button(direction, to) {{
if link: if link:
r = 0 r = 0
force = self.options.force force = self.options.force
for f in self.file_list: for f in self.file_list:
res = "{:d}x{:d}>".format(int(r), int(r)) 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 not os.path.exists(outfile):
if link: if link:
os.symlink( os.symlink("../{}".format(f), outfile)
"../{}".format(f),
outfile
)
continue continue
convargs = [ convargs = [
@@ -283,6 +318,3 @@ function create_button(direction, to) {{
sys.stdout.write(".") sys.stdout.write(".")
sys.stdout.flush() sys.stdout.flush()
subprocess.call(convargs) 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

View File

@@ -6,112 +6,112 @@ Released for free under the Creative Commons Attribution License
*/ */
body { body {
margin: 0; margin: 0;
padding: 0; padding: 0;
background-color: #eeeeee; background-color: #eeeeee;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-size: 12px; font-size: 12px;
color: #383838; color: #383838;
overflow-x: hidden; overflow-x: hidden;
} }
h1, h2, h3 { h1, h2, h3 {
margin: 0; margin: 0;
padding: 0; padding: 0;
font-weight: normal; font-weight: normal;
color: #000000; color: #000000;
} }
h1 { h1 {
font-size: 2em; font-size: 2em;
} }
h2 { h2 {
font-size: 2.4em; font-size: 2.4em;
} }
h3 { h3 {
font-size: 1.6em; font-size: 1.6em;
} }
p, ul, ol { p, ul, ol {
margin-top: 0; margin-top: 0;
line-height: 180%; line-height: 180%;
} }
ul, ol { ul, ol {
} }
a { a {
text-decoration: none; text-decoration: none;
color: #7EAD01; color: #7EAD01;
} }
a:hover { a:hover {
} }
#wrapper { #wrapper {
width: 100vw; width: 100vw;
margin: 0 auto; margin: 0 auto;
padding: 0; padding: 0;
} }
/* Header */ /* Header */
#header { #header {
clear: both; clear: both;
width: 100vw; width: 100vw;
height: 330px; height: 330px;
margin: 0 auto; margin: 0 auto;
padding: 0px; padding: 0px;
background: url(banner.jpg) no-repeat left top; background: url(banner.jpg) no-repeat left top;
background-size: cover; background-size: cover;
} }
/* Logo */ /* Logo */
#logo { #logo {
margin: 0; margin: 0;
padding: 0px 0px 0px 0px; padding: 0px 0px 0px 0px;
color: #000000; color: #000000;
} }
#logo h1, #logo p { #logo h1, #logo p {
margin: 0; margin: 0;
padding: 0; padding: 0;
color: #ffffff; color: #ffffff;
} }
#logo h1 { #logo h1 {
padding-top: 160px; padding-top: 160px;
letter-spacing: -1px; letter-spacing: -1px;
font-size: 3.8em; font-size: 3.8em;
word-break: break-all; word-break: break-all;
text-align: center; text-align: center;
} }
#logo p { #logo p {
margin: 0; margin: 0;
padding: 0px 0 0 60px; padding: 0px 0 0 60px;
font: normal 14px Georgia, "Times New Roman", Times, serif; font: normal 14px Georgia, "Times New Roman", Times, serif;
font-style: italic; font-style: italic;
color: #FFFFFF; color: #FFFFFF;
} }
#logo a { #logo a {
border: none; border: none;
background: none; background: none;
text-decoration: none; text-decoration: none;
color: #FFFFFF; color: #FFFFFF;
} }
/* Page */ /* Page */
#page { #page {
width: calc(100vw - 128px); width: calc(100vw - 128px);
margin: 0 auto; margin: 0 auto;
padding: 0px 0px 0px 0px; padding: 0px 0px 0px 0px;
} }
@media only screen and (max-width: 800px) { @media only screen and (max-width: 800px) {
#page { #page {
@@ -120,7 +120,7 @@ a:hover {
} }
#page-bgtop { #page-bgtop {
padding: 20px 0px; padding: 20px 0px;
} }
#page-bgbtm { #page-bgbtm {
@@ -130,11 +130,11 @@ a:hover {
#content { #content {
width: 100%; width: 100%;
padding: 30px 0px 0px 0px; padding: 30px 0px 0px 0px;
} }
.post { .post {
margin-bottom: 15px; margin-bottom: 15px;
border-top: lightgray dashed 2px; border-top: lightgray dashed 2px;
padding-top: 2px; padding-top: 2px;
} }
@@ -146,24 +146,24 @@ a:hover {
} }
.post .title { .post .title {
height: 38px; height: 38px;
margin-bottom: 10px; margin-bottom: 10px;
padding: 12px 0 0 0px; padding: 12px 0 0 0px;
letter-spacing: -.5px; letter-spacing: -.5px;
color: #000000; color: #000000;
} }
.post .title a { .post .title a {
color: #000000; color: #000000;
border: none; border: none;
} }
.post .meta { .post .meta {
padding: 5px 0px 5px 0px; padding: 5px 0px 5px 0px;
text-align: center; text-align: center;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-size: 13px; font-size: 13px;
font-weight: bold; font-weight: bold;
} }
.post .meta .name { .post .meta .name {
@@ -177,14 +177,14 @@ a:hover {
} }
.post .entry { .post .entry {
padding: 0px 5px 20px 5px; padding: 0px 5px 20px 5px;
text-align: justify; text-align: justify;
} }
.links { .links {
padding-top: 20px; padding-top: 20px;
font-size: 12px; font-size: 12px;
font-weight: bold; font-weight: bold;
} }
.center { .center {
@@ -199,32 +199,33 @@ a:hover {
} }
@media only screen and (max-width: 800px) { @media only screen and (max-width: 800px) {
.post_image { .post_image {
max-width: 100vw; max-height: calc(100vh - 2px);
max-width: calc(100vw - 2px);
} }
} }
/* Footer */ /* Footer */
#footer { #footer {
height: 50px; height: 50px;
margin: 0 auto; margin: 0 auto;
padding: 0px 0 15px 0; padding: 0px 0 15px 0;
background: #ECECEC; background: #ECECEC;
border-top: 1px solid #DEDEDE; border-top: 1px solid #DEDEDE;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
} }
#footer p { #footer p {
margin: 0; margin: 0;
padding-top: 20px; padding-top: 20px;
line-height: normal; line-height: normal;
font-size: 9px; font-size: 9px;
text-transform: uppercase; text-transform: uppercase;
text-align: center; text-align: center;
color: #A0A0A0; color: #A0A0A0;
} }
#footer a { #footer a {
color: #8A8A8A; color: #8A8A8A;
} }
/* navi */ /* navi */

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from mirva.mirva import Mirva
if __name__ == '__main__':
Mirva()

View File

@@ -1,2 +1,10 @@
[metadata] [metadata]
description-file = README.md 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

View File

@@ -1,18 +1,14 @@
from distutils.core import setup from distutils.core import setup
setup( setup(
name = 'mirva', name="mirva",
packages = ['mirva'], packages=["mirva"],
scripts = ['scripts/mirva', package_data={"": ["resources/*"]},
], include_package_data=True,
package_data={'':['resources/*']}, classifiers=[],
include_package_data=True, entry_points={
version = '20210820', "console_scripts": [
description = 'A tool to create a web gallery from a folder of images.', "mirva=mirva:main",
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',
) )