From cb142d3e306e032504bfc1cc841abec9a53d1516 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Sun, 14 Nov 2021 18:06:21 -0300 Subject: [PATCH] Restructure project --- .gitignore | 3 ++ README.md | 6 +++ build.sh | 6 +++ pyproject.toml | 6 +++ setup.cfg | 28 ++++++++++ src/fsub/__init__.py | 0 fsub => src/fsub/fsub.py | 113 ++++++++++++++++++++------------------- 7 files changed, 108 insertions(+), 54 deletions(-) create mode 100644 .gitignore create mode 100755 build.sh create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 src/fsub/__init__.py rename fsub => src/fsub/fsub.py (75%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b4aea5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist/ +*.egg-info/ +__pycache__/ diff --git a/README.md b/README.md index 92efae0..4d930cb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # fsub `fsub` is a Python script for cleaning, editing and fixing a SubRip (.srt) file +# Installation +Through Python's pip: +``` +pip install fsub +``` + # Usage ``` usage: fsub [-h] [-c] [-s MS] [-n] [-f FILE] file [file ...] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..2bc16e5 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh +rm -rv dist +python3 -m build + +# Upload to PyPI with: +# python3 -m twine upload --repository pypi dist/* diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..374b58c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..f0aa3ff --- /dev/null +++ b/setup.cfg @@ -0,0 +1,28 @@ +[metadata] +name = fsub +version = 0.0.1 +author = Augusto Lenz Gunsch +author_email = augustogunsch@tutanota.com +description = CLI SubRip editor +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/augustogunsch/fsub +project_urls = + Bug Tracker = https://github.com/augustogunsch/fsub/issues +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Operating System :: OS Independent + +[options] +package_dir = + = src +packages = find: +python_requires = >=3.9 + +[options.packages.find] +where = src + +[options.entry_points] +console_scripts = + fsub = fsub.fsub:main diff --git a/src/fsub/__init__.py b/src/fsub/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fsub b/src/fsub/fsub.py similarity index 75% rename from fsub rename to src/fsub/fsub.py index 767065f..da60466 100755 --- a/fsub +++ b/src/fsub/fsub.py @@ -188,67 +188,72 @@ def process_file(args, file): output.write(os.linesep) -parser = argparse.ArgumentParser( - description='Fix, edit and clean SubRip (.srt) files.', - add_help=True -) +def main(): + parser = argparse.ArgumentParser( + description='Fix, edit and clean SubRip (.srt) files.', + add_help=True + ) -parser.add_argument( - '-c', '--clean', - help='removes subtitles matching regular expressions ' + - 'listed in ~/.config/fsubrc (this is the default ' + - 'behavior if no other flag is passed)', - action='store_true' -) + parser.add_argument( + '-c', '--clean', + help='removes subtitles matching regular expressions ' + + 'listed in ~/.config/fsubrc (this is the default ' + + 'behavior if no other flag is passed)', + action='store_true' + ) -parser.add_argument( - '-s', '--shift', - help='shifts all subtitles by MS milliseconds, which ' + - 'may be positive or negative', - metavar='MS', - action='store', - type=int -) + parser.add_argument( + '-s', '--shift', + help='shifts all subtitles by MS milliseconds, which ' + + 'may be positive or negative', + metavar='MS', + action='store', + type=int + ) -parser.add_argument( - '-n', '--no-html', - help='strips HTML tags from subtitles content', - action='store_true' -) + parser.add_argument( + '-n', '--no-html', + help='strips HTML tags from subtitles content', + action='store_true' + ) -parser.add_argument( - '-f', '--config-file', - help='overwrites the default config file (~/.config/fsubrc)', - metavar='FILE', - action='store', - type=argparse.FileType('r') -) + parser.add_argument( + '-f', '--config-file', + help='overwrites the default config file (~/.config/fsubrc)', + metavar='FILE', + action='store', + type=argparse.FileType('r') + ) -parser.add_argument( - 'files', - help='list of input files (they all must be SubRip files)', - metavar='file', - type=argparse.FileType('rb+'), - nargs='+' -) + parser.add_argument( + 'files', + help='list of input files (they all must be SubRip files)', + metavar='file', + type=argparse.FileType('rb+'), + nargs='+' + ) -args = parser.parse_args() + args = parser.parse_args() -# Make sure --clean is the default -if not args.shift and not args.no_html: - args.clean = True + # Make sure --clean is the default + if not args.shift and not args.no_html: + args.clean = True -# Validate options -if not args.clean and args.config_file: - print('-f requires -c', file=sys.stderr) - exit(1) + # Validate options + if not args.clean and args.config_file: + print('-f requires -c', file=sys.stderr) + exit(1) -# Check if all files are .srt -for file in args.files: - if file.name[-4:] != '.srt': - print('File {} is not a SubRip file'.format(file.name), - file=sys.stderr) - sys.exit(1) + # Check if all files are .srt + for file in args.files: + if file.name[-4:] != '.srt': + print('File {} is not a SubRip file'.format(file.name), + file=sys.stderr) + sys.exit(1) -for file in args.files: - process_file(args, file) + for file in args.files: + process_file(args, file) + + +if __name__ == '__main__': + main()