diff --git a/config.py b/config.py index b3b1bd3..107ed73 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,32 @@ - - -DEFAULT_DESCRIPTION = 'Simple math package' DEFAULT_AUTHOR = 'Maximilian Keßler' + +LICENSE = [ + 'Copyright © {year} {copyright_holders}', + '', + 'Permission is hereby granted, free of charge, to any person obtaining a copy', + 'of this software and associated documentation files (the “Software”), to deal', + 'in the Software without restriction, including without limitation the rights', + 'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell', + 'copies of the Software, and to permit persons to whom the Software is', + 'furnished to do so, subject to the following conditions:', + 'The above copyright notice and this permission notice shall be included in all', + 'copies or substantial portions of the Software.', + '', + 'THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR', + 'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,', + 'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE', + 'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER', + 'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,', + 'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE', + 'SOFTWARE.' +] + +PACKAGE_INFO_TEXT = [ + "This LaTeX package is free software and distributed under the MIT License. You", + "may use it freely for your purposes. The latest version of the package can be", + "obtained via GitHub under", + " https://github.com/kesslermaximilian/LatexPackages", + "For further information see the url above.", + "Reportings of bugs, suggestions and improvements are welcome, see the README", + "at the Git repository for further information." +] diff --git a/enums.py b/enums.py index b062c3a..16244b9 100644 --- a/enums.py +++ b/enums.py @@ -3,13 +3,13 @@ from enum import Enum class Attributes(Enum): package_name_raw = 'package_name_raw' - description = 'description' author = 'author' author_acronym = 'author_acronym' package_name = 'package_name' package_prefix = 'package_prefix' file_name = 'file_name' date = 'date' + year = 'year' class Args(Enum): diff --git a/package_formatter.py b/package_formatter.py index bb65057..c77e29d 100644 --- a/package_formatter.py +++ b/package_formatter.py @@ -3,14 +3,13 @@ import re from pathlib import Path from typing import Dict from datetime import * -from config import DEFAULT_DESCRIPTION, DEFAULT_AUTHOR +from config import DEFAULT_AUTHOR from enums import Attributes, Args class PackageFormatter: - def __init__(self, package_name: str, description: str = DEFAULT_DESCRIPTION, author: str = DEFAULT_AUTHOR): + def __init__(self, package_name: str, author: str = DEFAULT_AUTHOR): self.package_name_raw = package_name - self.description = description self.author = author author_parts = self.author.lower().replace('ß', 'ss').split(' ') self.author_acronym = author_parts[0][0] + author_parts[-1] @@ -19,6 +18,7 @@ class PackageFormatter: self.package_prefix = self.package_name.replace('-', '@') + '@' self.file_name = self.package_name + '.sty' self.date = datetime.now().strftime('%Y/%m/%d') + self.year = int(datetime.now().strftime('%Y')) self.replace_dict: Dict = {} self.arg_replace_dict: Dict = {} diff --git a/replacements.py b/replacements.py index eed331d..6b11782 100644 --- a/replacements.py +++ b/replacements.py @@ -1,17 +1,25 @@ from enums import Attributes, Args from package_formatter import PackageFormatter +from config import LICENSE, PACKAGE_INFO_TEXT def make_default_commands(package_formatter: PackageFormatter): + header = '%'*80 + '\n' + '\n'.join(map(lambda line: '% ' + line, LICENSE + [''] + PACKAGE_INFO_TEXT))\ + + '\n' + '%'*80 + '\n' \ + + '\\NeedsTeXFormat{{LaTeX2e}}\n' \ + '\\ProvidesPackage{{{package_name}}}[{date} - {description}]\n\n' + package_formatter.add_arg_replacement( + 1, 'header', + header, + package_name=Attributes.package_name, + date=Attributes.date, + description=Args.one, + year=Attributes.year, + copyright_holders=Attributes.author + ) package_formatter.add_replacement('package name', '{}', Attributes.package_name) package_formatter.add_replacement('package prefix', '{}', Attributes.package_prefix) package_formatter.add_replacement('file name', '{name}', name=Attributes.file_name) - package_formatter.add_replacement('header', '\\NeedsTeXFormat{{LaTeX2e}}\n' - '\\ProvidesPackage{{{name}}}[{} - {}]\n' - '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%', - Attributes.date, - Attributes.description, - name=Attributes.package_name) package_formatter.add_replacement('date', '{}', Attributes.date) package_formatter.add_replacement('author', '{}', Attributes.author) package_formatter.add_arg_replacement(1, 'newif', r'\newif\if{prefix}{condition}', @@ -22,3 +30,5 @@ def make_default_commands(package_formatter: PackageFormatter): condition=Args.one) package_formatter.add_arg_replacement(1, 'info', r'\PackageInfo{{{name}}}{{{info}}}', name=Attributes.package_name, info=Args.one) + package_formatter.add_arg_replacement(1, 'warning', r'\PackageWarning{{{name}}}{{{warning}}}', + name=Attributes.package_name, warning=Args.one)