Compare commits

...

2 Commits

Author SHA1 Message Date
crunk 4654ced5e8 change README 1 day ago
crunk e93a3e3b28 refactoring 1 day ago
  1. 35
      README.md
  2. 45
      distribusi/distribusi.py
  3. 19
      distribusi/templates/page_template.py

35
README.md

@ -8,6 +8,15 @@ index functions featured in several web servers. It works by traversing the
file system and directory hierarchy to automatically list all the files in the file system and directory hierarchy to automatically list all the files in the
directory and providing them with html classes and tags for easy styling. directory and providing them with html classes and tags for easy styling.
## This distribusi fork powers distribusi-verse
If you want to run distribusi on its own go here: [original](https://git.vvvvvvaria.org/varia/distribusi)
This version is used to power [distribusi-verse](https://git.vvvvvvaria.org/Toolsheds/distribusi-verse) which folds this tool in a webapplication.
To make this work a little easier this version has certain options removed that are handy
and available in the standalone version.
For other distribusi like softwares also checkout [distribusi-go](https://git.coopcloud.tech/decentral1se/distribusi-go)
## Requirements ## Requirements
While a Pip install will pull in Python dependencies, you might need system While a Pip install will pull in Python dependencies, you might need system
@ -85,29 +94,3 @@ The contribution consisted of setting up distribusi.ruruhuis.nl (distribusi is b
> "Individuals collecting fragments each have their own folder. When they put a story, picture, audio, or video file inside a folder, each fragment is assigned a serial number, and gets accumulated in the fragments of hospitality website.The fragments connect us. We hope that we can choose the “nature and attitude” of the medium that mediates our connection." > "Individuals collecting fragments each have their own folder. When they put a story, picture, audio, or video file inside a folder, each fragment is assigned a serial number, and gets accumulated in the fragments of hospitality website.The fragments connect us. We hope that we can choose the “nature and attitude” of the medium that mediates our connection."
[https://fragments1444.ink/about.html](source) [https://fragments1444.ink/about.html](source)
## Change It
You'll need to get a copy of the repository and then do an [editable] install:
[editable]: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
```bash
$ git clone https://git.vvvvvvaria.org/varia/distribusi.git && cd distribusi
$ python3 -m venv .venv && source .venv/bin/activate
$ pip install -e .
```
You're then ready to make your changes and experiment with them.
## Release It
You'll need a [PyPi](https://pypi.org/) account and to be added as a maintainer.
Please ask around @ Varia for who has PyPi access.
```
$ # ... change the version number in setup.py ... #
$ pip install twine wheel
$ make publish
```

45
distribusi/distribusi.py

@ -100,19 +100,12 @@ def check_distribusi_index(args, index):
return True return True
def write_index(args, index, html): def write_index_html(args, index, html):
with open(index, "w") as index_file: with open(index, "w") as index_file:
if args.style: styled_html_head = html_head.format(cssfile=args.style)
file_style = open(args.style, "r")
style = file_style.read()
styled_html_head = html_head % style
else:
styled_html_head = html_head % ""
index_file.write(styled_html_head) index_file.write(styled_html_head)
for line in html: for line in html:
index_file.write(line + "\n") index_file.write(line + "\n")
index_file.write(html_footer) index_file.write(html_footer)
@ -187,6 +180,23 @@ def remove_hidden_files_and_folders(dirs, files):
return dirs, files return dirs, files
def is_skipped_file(name, args):
if "index.html" in name:
return True
if name.endswith("_thumbnail.jpg"):
return True
if name.endswith("_alttext.txt"):
return True
if name.endswith("_dv_description.txt"):
return True
if args.style in name:
return True
def distribusify(args, directory): # noqa def distribusify(args, directory): # noqa
for root, dirs, files in os.walk(directory): for root, dirs, files in os.walk(directory):
html = [] html = []
@ -208,16 +218,7 @@ def distribusify(args, directory): # noqa
print("Generating directory listing for", root) print("Generating directory listing for", root)
for name in sorted(files): for name in sorted(files):
if "index.html" in name: if is_skipped_file(name, args):
continue
if name.endswith("_thumbnail.jpg"):
continue
if name.endswith("_alttext.txt"):
continue
if name.endswith("_dv_description.txt"):
continue continue
full_path = os.path.join(root, name) full_path = os.path.join(root, name)
@ -271,8 +272,4 @@ def distribusify(args, directory): # noqa
html.insert(0, format_div(args, "dir", "dir", tag, "folder")) html.insert(0, format_div(args, "dir", "dir", tag, "folder"))
index = os.path.join(root, "index.html") index = os.path.join(root, "index.html")
if os.path.exists(index): write_index_html(args, index, html)
if check_distribusi_index(args, index):
write_index(args, index, html)
elif not os.path.exists(index):
write_index(args, index, html)

19
distribusi/templates/page_template.py

@ -1,25 +1,16 @@
html_head = """ html_head = '''\
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<!-- Generated with distribusi https://git.vvvvvvaria.org/crunk/distribusi --> <!-- Generated with distribusi https://git.vvvvvvaria.org/crunk/distribusi -->
<meta name="generator" content="distribusi" /> <meta name="generator" content="distribusi" />
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8">
<style> <link rel="stylesheet" href="{cssfile}" crossorigin="anonymous">
.image{max-width: 100%%;}
.pdf object{width:640px;height: 640px;}
.dir::before{content:"📁 ";font-size:18px;}
.filename{display:block;font-family:mono;}
.unkown-file::before{content:"📄 ";font-size:18px;}
div{max-width: 640px;display:inline-block;vertical-align:top;margin:1em;padding:1em;}
video {width:640px;max-height:640px;}
%s
</style>
</head> </head>
<body> <body>
""" '''
html_footer = """ html_footer ='''\
</body> </body>
</html> </html>
""" '''

Loading…
Cancel
Save