Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from CoolCoderCarl/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
CoolCoderCarl authored May 20, 2022
2 parents 26cab14 + 5844559 commit 5a3a347
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 38 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: Build

on:
pull_request:
branches: [ main ]
branches: [ develop ]
paths-ignore:
- 'README.md'
- '.gitignore'
- 'changelog.json'

jobs:

Expand All @@ -12,7 +16,10 @@ jobs:
outputs:
get_current_tag: ${{ steps.set_current_tag_id.outputs.current_tag }}
steps:
- uses: actions/checkout@v2

- name: Checkout code
uses: actions/checkout@v2

- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.0
Expand All @@ -24,11 +31,16 @@ jobs:
with:
labels: develop

- uses: actions-ecosystem/action-add-assignees@v1
with:
assignees: ${{ github.actor }}
github_token: ${{ secrets.REPOS_TOKEN }}

- name: Set tag version to output
id: set_current_tag_id
run: echo "::set-output name=current_tag::${{ steps.tag_version.outputs.new_tag }}"

- name: Step To run on failure
- name: Notify if failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
Expand Down Expand Up @@ -58,7 +70,10 @@ jobs:
ASSET_MIME: application/x-binary

steps:
- uses: actions/checkout@v2

- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
Expand All @@ -79,7 +94,7 @@ jobs:
path: ./dist/${{ matrix.OUT_FILE_NAME }}
retention-days: 1

- name: Step To run on failure
- name: Notify if failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Code Quality

on:
push:
branches: [ develop ]
branches: [ feature/* ]

jobs:
code_quality:
Expand All @@ -15,18 +15,15 @@ jobs:
uses: actions/checkout@v2

- name: Run script
run: |
pip install -r requirements.txt
run: pip install -r requirements.txt

- name: Black check
run:
black --check .
run: black --check .

- name: Isort check
run:
isort --check .
run: isort --check .

- name: Step To run on failure
- name: Notify if failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/ignore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Ignore and notify

on:
push:
branches:
- main
- develop
paths-ignore:
- 'README.md'
- '.gitignore'
- 'changelog.json'
- 'test-pyt-ser.service'

jobs:

telegram:
runs-on: ubuntu-latest
name: Notify after update
steps:

- name: Notify after released image
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: html
message: |
${{ github.actor }} created commit:
<b>WorkFlows:</b> <a href="https://github.com/${{ github.repository }}/actions/">ActionsList</a>
Repository: ${{ github.repository }}
Branch: ${{ github.ref }}
<b>Something were changed</b>
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
15 changes: 11 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Release

on:
push:
pull_request:
branches: [ main ]
paths-ignore:
- 'README.md'
- '.gitignore'
- 'changelog.json'

jobs:

Expand All @@ -13,7 +17,10 @@ jobs:
get_release_url: ${{ steps.set_release_url.outputs.release_url }}
get_current_tag: ${{ steps.set_current_tag_id.outputs.current_tag }}
steps:
- uses: actions/checkout@v2

- name: Checkout code
uses: actions/checkout@v2

- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.0
Expand Down Expand Up @@ -46,7 +53,7 @@ jobs:
id: set_current_tag_id
run: echo "::set-output name=current_tag::${{ steps.tag_version.outputs.new_tag }}"

- name: Step To run on failure
- name: Notify if failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
Expand Down Expand Up @@ -110,7 +117,7 @@ jobs:
asset_name: ${{ matrix.OUT_FILE_NAME }}
asset_content_type: ${{ matrix.ASSET_MIME }}

- name: Step To run on failure
- name: Notify if failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
Expand Down
80 changes: 59 additions & 21 deletions butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
files_extension = [
".txt",
".ini",
".md",
".doc",
".docx",
".rtf",
Expand All @@ -24,6 +25,7 @@
".iso",
".mkv",
".mov",
".mp4",
".bmp",
".jpg",
".png",
Expand All @@ -39,18 +41,20 @@

archives_extension = [".zip", ".7z", ".gz", ".bz", ".gzip", ".bzip", ".iso"]

target_dir_name = "ALL"


# Delete files by mask or exclude deletion
def clean_the_dir(path_to_clean: str):
"""
Clean the target directory, but not delete directory itself
:param path_to_clean:
:return:
"""
if args.clean == "/":
print("It is totally not great idea to remove all things")
exit(1)
else:
for filename in os.listdir(path_to_clean):
path = os.path.join(path_to_clean, filename)
if "butler" in (path.split("/")[-1]):
if "butler" in (path.split("/")[-1]).lower():
print("Skipped " + path.split("/")[-1])
else:
try:
Expand All @@ -60,21 +64,30 @@ def clean_the_dir(path_to_clean: str):


def group_up_files(new_dir_name: str):
if args.dir == "/":
"""
Group up files in target directory
Create directory for files in target directory with ALL.EXT template according the files extensions
Move all files to relevant directory
:param new_dir_name:
:return:
"""
if args.source == "/":
print("It is totally not great idea to modify all things")
exit(1)
else:
for filename in os.listdir(args.dir):
if "butler" in filename:
for filename in os.listdir(args.source):
if "butler" in filename.lower():
print("Skipped " + filename)
else:
for ext in files_extension:
if filename.endswith(ext):
file_path = os.path.join(args.dir, filename)
if args.dir == ".":
new_dir_path = new_dir_name + ext.upper()
file_path = os.path.join(args.source, filename)
if args.source == ".":
new_dir_path = new_dir_name.upper() + ext.upper()
else:
new_dir_path = args.dir + new_dir_name + ext.upper()
new_dir_path = (
args.source + new_dir_name.upper() + ext.upper()
)
try:
os.mkdir(new_dir_path)
except OSError:
Expand All @@ -83,12 +96,18 @@ def group_up_files(new_dir_name: str):


def create_archive(dir_to_archive: str):
"""
Archive all files in target directory & add archive near the butler.exe
Ignore files with archive extensions
:param dir_to_archive:
:return:
"""
now = datetime.now()
date_time = now.strftime("%m.%d.%Y_%H.%M.%S")
with ZipFile(str(date_time) + ".zip", "w") as zip_obj:
for folder_name, sub_folders, filenames in os.walk(dir_to_archive):
for filename in filenames:
if "butler" in filename:
if "butler" in filename.lower():
print("Skipped " + filename)
else:
for a_ext in archives_extension:
Expand All @@ -98,32 +117,51 @@ def create_archive(dir_to_archive: str):
zip_obj.write(zip_path, basename(zip_path))


parser = argparse.ArgumentParser(
root_parser = argparse.ArgumentParser(
prog="butler",
description="""The Butler helps keep the castle clean and tidy""",
epilog="""(c) CoolCoderCarl""",
)

parser.add_argument(
"--clean", help="Clean target directory. Example /tmp/, both slash required"
root_parser.add_argument(
"-c",
"--clean",
help="Clean target directory. Example /tmp/, both slash required",
type=str,
)

group_up_subparser = root_parser.add_subparsers(
title="group_up_subparser",
dest="group",
help="Group up files in target dir with target dir name",
)

parser.add_argument(
"--dir", help="Dir to group up the files. Example /tmp/, both slash required"
group_up_parser = group_up_subparser.add_parser(
"group", help="Dir to group up the files."
)
group_up_parser.add_argument(
"--source", help="Source dir name. Example /tmp/, both slash required", type=str
)
group_up_parser.add_argument("--target", help="Target dir name. Example ALL", type=str)


parser.add_argument(
root_parser.add_argument(
"-a",
"--archive",
help="Create archive from target directory. Example /tmp/, both slash required",
type=str,
)

args = parser.parse_args()
args = root_parser.parse_args()


if __name__ == "__main__":
if args.clean:
clean_the_dir(args.clean)
elif args.dir:
group_up_files(target_dir_name)
elif args.group:
group_up_files(args.target)
elif args.archive:
create_archive(args.archive)
# print(args.group)
# print(args.source)
# print(args.target)

0 comments on commit 5a3a347

Please sign in to comment.