updated
This commit is contained in:
33
Makefile
Normal file
33
Makefile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
|
||||||
|
help: ## *:・゚✧*:・゚✧ This help *:・゚✧*:・゚✧
|
||||||
|
@printf "\033[36;1m %14s \033[0;32;1m %s\033[0m\n" Target Description
|
||||||
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
|
||||||
|
awk ' \
|
||||||
|
BEGIN {FS = ":.*?## "}; \
|
||||||
|
{ if ( $$1 != "-") { \
|
||||||
|
printf "\033[31;1;40m[ \033[36;1;40m%14s \033[31;1;40m]\033[0;32;1m %s\033[0m\n", $$1, $$2 \
|
||||||
|
} else { \
|
||||||
|
printf " \033[0;33;1m=^= %-25s =^=\033[0m\n", $$2 \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
'
|
||||||
|
|
||||||
|
-: ## Building
|
||||||
|
###################################
|
||||||
|
|
||||||
|
clean: ## Clean build folders
|
||||||
|
rm -r build tsmark.egg-info
|
||||||
|
|
||||||
|
build: ## Build
|
||||||
|
hatchling build
|
||||||
|
|
||||||
|
pip: ## Install with pip
|
||||||
|
pip install .
|
||||||
|
|
||||||
|
pipx: ## Install with pipx
|
||||||
|
pipx install -f .
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -10,11 +10,8 @@ Basic function:
|
|||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
- Create a folder that is publicily visible on a web server, like Nginx.
|
- Install module with pip or pipx
|
||||||
- Copy the flit.example as executable `flit`, and add the public URL in the
|
- Create a folder that is publicily visible on a web server, for example Nginx.
|
||||||
script.
|
|
||||||
- Have the flit.py in the same folder.
|
|
||||||
- Add a symlink to flit script so that it is in the PATH, i.e. `ln -s $(pwd)/flit ~/.local/bin/flit`
|
|
||||||
- Add `flit del` to daily cron
|
- Add `flit del` to daily cron
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
|
|
||||||
pwd=$( dirname $( readlink -f $0 ) )
|
|
||||||
python3 "$pwd"/flit.py --home "/path/to/share" --root "https://your.server/and.path" "$@"
|
|
||||||
7
flit/__init__.py
Normal file
7
flit/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from flit.flit import main
|
||||||
|
|
||||||
|
__version__ = "20241202.0"
|
||||||
|
|
||||||
|
|
||||||
|
def flit():
|
||||||
|
main()
|
||||||
@@ -1,27 +1,40 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from datetime import datetime, timedelta
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import string
|
import string
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
import json
|
|
||||||
|
|
||||||
"""FLIT: Fluttering folders for simple file sharing.
|
"""FLIT: Fluttering folders for simple file sharing.
|
||||||
|
|
||||||
The script maintains a set of folders, named so that they are hard to guess,
|
The script maintains a set of folders, named so that they are hard to guess,
|
||||||
and contents are deleted after expiration date.
|
and contents are deleted after expiration date.
|
||||||
|
|
||||||
Attributes:
|
|
||||||
CONFIG (str): Configuration file name stored in each shared folder.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__version__ = "20241202.0"
|
||||||
|
|
||||||
|
|
||||||
|
GLOBAL_CONFIG = os.path.expanduser("~/.config/flit/config.json")
|
||||||
CONFIG = ".flit.json"
|
CONFIG = ".flit.json"
|
||||||
|
|
||||||
|
|
||||||
def parse_opts():
|
def write_default_global_config():
|
||||||
|
os.makedirs(os.path.dirname(GLOBAL_CONFIG), exist_ok=True)
|
||||||
|
with open(os.path.join(GLOBAL_CONFIG), "wt") as fp:
|
||||||
|
json.dump({"ROOT_URL": "https://my.website.net", "HOME_DIR": os.getcwd()}, fp, indent=2, sort_keys=True)
|
||||||
|
print(f"New template config written. See '{GLOBAL_CONFIG}'")
|
||||||
|
|
||||||
|
|
||||||
|
def read_default_global_config():
|
||||||
|
with open(os.path.join(GLOBAL_CONFIG), "rt") as fp:
|
||||||
|
return json.load(fp)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_opts(global_config):
|
||||||
"""Options parser
|
"""Options parser
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -38,9 +51,7 @@ def parse_opts():
|
|||||||
print("")
|
print("")
|
||||||
# retrieve subparsers from parser
|
# retrieve subparsers from parser
|
||||||
subparsers_actions = [
|
subparsers_actions = [
|
||||||
action
|
action for action in parser._actions if isinstance(action, argparse._SubParsersAction)
|
||||||
for action in parser._actions
|
|
||||||
if isinstance(action, argparse._SubParsersAction)
|
|
||||||
]
|
]
|
||||||
for subparsers_action in subparsers_actions:
|
for subparsers_action in subparsers_actions:
|
||||||
# get all subparsers and print help
|
# get all subparsers and print help
|
||||||
@@ -51,9 +62,7 @@ def parse_opts():
|
|||||||
parser.exit()
|
parser.exit()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(add_help=False)
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
parser.add_argument(
|
parser.add_argument("--help", "-h", action=_HelpAction, help="Show this help message and exit")
|
||||||
"--help", "-h", action=_HelpAction, help="Show this help message and exit"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"-v",
|
"-v",
|
||||||
@@ -69,16 +78,16 @@ def parse_opts():
|
|||||||
action="store",
|
action="store",
|
||||||
dest="root",
|
dest="root",
|
||||||
type=str,
|
type=str,
|
||||||
default="",
|
default=global_config["ROOT_URL"],
|
||||||
help="Root address for printing URLS",
|
help=f"Root address for printing URLS. Your webserver should map this to --home. Default '%(default)s' from {GLOBAL_CONFIG}",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--home",
|
"--home",
|
||||||
action="store",
|
action="store",
|
||||||
dest="home",
|
dest="home",
|
||||||
type=str,
|
type=str,
|
||||||
default=None,
|
default=global_config["HOME_DIR"],
|
||||||
help="Home folder for flit. This is where folders are created, and --root should point to in the filesystem. Defaults to script location",
|
help=f"Home folder for flit. This is where the folders are created. Default '%(default)s' from {GLOBAL_CONFIG}",
|
||||||
)
|
)
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(dest="command", help="Command defaults to add")
|
subparsers = parser.add_subparsers(dest="command", help="Command defaults to add")
|
||||||
@@ -157,9 +166,7 @@ def random_name():
|
|||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
existing_names = [c["name"] for c in get_folders()]
|
existing_names = [c["name"] for c in get_folders()]
|
||||||
existing_numbers = [
|
existing_numbers = [tryint(num[0:3]) for num in existing_names if tryint(num[0:3]) != None]
|
||||||
tryint(num[0:3]) for num in existing_names if tryint(num[0:3]) != None
|
|
||||||
]
|
|
||||||
if len(existing_numbers) == 0:
|
if len(existing_numbers) == 0:
|
||||||
index = 0
|
index = 0
|
||||||
else:
|
else:
|
||||||
@@ -403,8 +410,14 @@ def tryint(s):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
opts = parse_opts()
|
try:
|
||||||
|
global_config = read_default_global_config()
|
||||||
|
except FileNotFoundError:
|
||||||
|
write_default_global_config()
|
||||||
|
global_config = read_default_global_config()
|
||||||
|
|
||||||
|
opts = parse_opts(global_config)
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
if opts.home == None:
|
if opts.home == None:
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
35
pyproject.toml
Normal file
35
pyproject.toml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "flit"
|
||||||
|
dynamic = ["version"]
|
||||||
|
description = 'Create fluttering folders'
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
license = "MIT"
|
||||||
|
keywords = []
|
||||||
|
authors = [
|
||||||
|
{ name = "Q", email = "q@six9.net" },
|
||||||
|
]
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 4 - Beta",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
|
]
|
||||||
|
dependencies = ["tqdm"]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
flit = "flit:flit"
|
||||||
|
|
||||||
|
[tool.hatch.version]
|
||||||
|
path = "flit/__init__.py"
|
||||||
|
|
||||||
|
[tool.hatch.build.targets.wheel]
|
||||||
|
packages = ["flit"]
|
||||||
Reference in New Issue
Block a user