Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancements #29

Merged
merged 10 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it to handler, is that OK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

- `main` function in `__main__.py`
- `README.md`
- `clear` function `functions.py`
Expand Down
64 changes: 51 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

## Overview
<p align="justify">
DMeta is an open source Python package that provides ... TODO
DMeta is an open source Python package that removes metadata of microsoft office files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it to ... Microsoft Office ..., is that OK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, go ahead.

</p>
<table>
<tr>
Expand Down Expand Up @@ -84,30 +84,68 @@ DMeta is an open source Python package that provides ... TODO
- Run `pip install .`

## Usage
### Programmatically
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using ### In Python instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead and apply yourself, then finally ping me, I will review them.

#### 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(DOCX_FILE_PATH, DOCX_FILE_PATH)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of them should be config, I will fix it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shit, yes you are right, the first one I guess.

```

### 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) | &#x2705; |


## Issues & bug reports

Just fill an issue and describe it. We'll check it ASAP! or send an email to [[email protected]](mailto:[email protected] "[email protected]").
Expand Down
20 changes: 7 additions & 13 deletions dmeta/__main__.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -11,9 +10,6 @@ def main():

:return: None
"""
tprint("DMeta")
tprint("V:" + DMETA_VERSION)
dmeta_help()
parser = argparse.ArgumentParser()
parser.add_argument(
'--clear',
Expand Down Expand Up @@ -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"
7 changes: 6 additions & 1 deletion dmeta/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Loading