diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 42ab46e..65c823a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,30 @@ jobs: run: | python -m pip install --upgrade pip pip install . + - name: CLI Tests - Version Check + run: | + python -m dmeta --version + dmeta -v + - name: CLI Tests - Clear single .docx file + run: | + dmeta --clear "tests/test_a.docx" + ls ./tests + - name: CLI Tests - Clear all .docx files + run: | + cd ./tests + dmeta --clear-all + ls . + cd - + - name: CLI Tests - Update single .docx file + run: | + dmeta --update "tests/test_a.docx" --config "tests/config.json" + ls ./tests + - name: CLI Tests - Update all .docx files + run: | + cd ./tests + dmeta --update-all --config "./config.json" + ls . + cd - - name: Test requirements Installation run: | python otherfiles/requirements-splitter.py diff --git a/CHANGELOG.md b/CHANGELOG.md index b81801c..1ed8554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed ## [0.1] - 2024-05-29 ### Added +- `CLI` handler - `main` function in `__main__.py` - `README.md` - `clear` function `functions.py` diff --git a/README.md b/README.md index 63f60f0..9cb1143 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@ Codecov - - PyPI version + + PyPI version built with Python3 - - Discord Channel + + Discord Channel @@ -35,14 +35,14 @@ ## Overview

-DMeta is an open source Python package that provides ... TODO +DMeta is an open source Python package that removes metadata of Microsoft Office files.

@@ -50,7 +50,7 @@ DMeta is an open source Python package that provides ... TODO @@ -84,30 +84,68 @@ DMeta is an open source Python package that provides ... TODO - Run `pip install .` ## Usage +### In Python +#### Clear metadata for a .docx file +```python +import os +from dmeta.functions import clear + +DOCX_FILE_PATH = os.path.join(os.getcwd(), "sample.docx") +clear(DOCX_FILE_PATH) +``` +#### Clear metadata for all existing .docx files in the current directory +```python +from dmeta.functions import clear_all +clear_all() +``` +#### Update metadata for a .docx file +```python +import os +from dmeta.functions import update + +CONFIG_FILE_PATH = os.path.join(os.getcwd(), "config.json") +DOCX_FILE_PATH = os.path.join(os.getcwd(), "sample.docx") +update(CONFIG_FILE_PATH, DOCX_FILE_PATH) +``` + +### Update metadata for all existing .docx files in the current directory +```python +import os +from dmeta.functions import update_all + +CONFIG_FILE_PATH = os.path.join(os.getcwd(), "config.json") +update_all(CONFIG_FILE_PATH) +``` + +### CLI +⚠️ You can use `dmeta` or `python -m dmeta` to run this program +#### Version +```console +dmeta -v +dmeta --version +``` ### Clear metadata for a .docx file -```pycon ->>> TODO +```console +dmeta --clear "./test_a.docx" ``` -### Clear metadata for all existing .docx files -```pycon ->>> TODO +### Clear metadata for all existing .docx files in the current directory +```console +dmeta --clear-all ``` ### Update metadata for a .docx file -```pycon ->>> TODO +```console +dmeta --update "./test_a.docx" --config "./config.json" ``` -### Update metadata for all existing .docx files -```pycon ->>> TODO +### Update metadata for all existing .docx files in the current directory +```console +dmeta --update-all --config "./config.json" ``` - ## Supported files | File format | support | | ---------------- | ---------------- | | Microsoft word office(.docx) | ✅ | - ## Issues & bug reports Just fill an issue and describe it. We'll check it ASAP! or send an email to [info@openscilab.com](mailto:info@openscilab.com "info@openscilab.com"). @@ -116,8 +154,8 @@ Just fill an issue and describe it. We'll check it ASAP! or send an email to [in You can also join our discord server - - Discord Channel + + Discord Channel @@ -131,4 +169,4 @@ Give a ⭐️ if this project helped you! ### Donate to our project If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-) . -DMeta Donation \ No newline at end of file +DMeta Donation diff --git a/dmeta/__main__.py b/dmeta/__main__.py index 90d2956..f65becb 100644 --- a/dmeta/__main__.py +++ b/dmeta/__main__.py @@ -1,7 +1,6 @@ """DMeta main.""" import argparse -from art import tprint -from dmeta.functions import run_dmeta, dmeta_help +from dmeta.functions import run_dmeta from dmeta.params import DMETA_VERSION @@ -11,9 +10,6 @@ def main(): :return: None """ - tprint("DMeta") - tprint("V:" + DMETA_VERSION) - dmeta_help() parser = argparse.ArgumentParser() parser.add_argument( '--clear', @@ -48,16 +44,14 @@ def main(): type=str, help="the `config` command specifices the way metadata in the .docx files get updated." ) - # parse the arguments from the standard input - args = parser.parse_args() + parser.add_argument('--version', help="version", action='store_true', default=False) + parser.add_argument('-v', help="version", action='store_true', default=False) + args = parser.parse_known_args()[0] + if args.version or args.v: + print(DMETA_VERSION) + return run_dmeta(args) if __name__ == "__main__": main() - -# testcases: -# dmeta --clear "test.docx" -# dmeta --clear-all -# dmeta --update "test.docx" --config "cnf.json" -# dmeta --update-all --config "cnf.json" diff --git a/dmeta/functions.py b/dmeta/functions.py index e957c25..cc34f6d 100644 --- a/dmeta/functions.py +++ b/dmeta/functions.py @@ -3,9 +3,10 @@ import os import shutil import zipfile +from art import tprint from .util import remove_format, extract_docx, read_json import defusedxml.ElementTree as ET -from .params import CORE_XML_MAP, APP_XML_MAP, OVERVIEW +from .params import CORE_XML_MAP, APP_XML_MAP, OVERVIEW, DMETA_VERSION def clear(docx_file_name): @@ -169,3 +170,7 @@ def run_dmeta(args): print("when using the `update-all` command, you should set the .json config file through the --config command") else: update_all(args.config[0]) + else: + tprint("DMeta") + tprint("V:" + DMETA_VERSION) + dmeta_help()
PyPI Counter - - + +
Github Stars - +