From a4f6add34d48ddc50cf09877c4ffb4e7bf589ede Mon Sep 17 00:00:00 2001
From: CoolCoderCarl <123qwekir2wl@gmail.com>
Date: Thu, 12 May 2022 18:47:18 +0300
Subject: [PATCH 1/6] Separate ci.yaml & build.yaml; fix issue in butler.py
---
.github/workflows/build.yaml | 142 +++++++++++++++++++++++++++++++++++
.github/workflows/ci.yaml | 125 +-----------------------------
butler.py | 11 ++-
3 files changed, 150 insertions(+), 128 deletions(-)
create mode 100644 .github/workflows/build.yaml
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
new file mode 100644
index 0000000..eef5c9a
--- /dev/null
+++ b/.github/workflows/build.yaml
@@ -0,0 +1,142 @@
+name: CI
+
+on:
+ push:
+ branches: [ main ]
+
+jobs:
+
+ release:
+ name: Create Release
+ runs-on: ubuntu-latest
+ outputs:
+ 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: Bump version and push tag
+ id: tag_version
+ uses: mathieudutour/github-tag-action@v6.0
+ with:
+ github_token: ${{ secrets.REPOS_TOKEN }}
+
+ - name: Create Release
+ id: create_release
+ uses: actions/create-release@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.REPOS_TOKEN }}
+ with:
+ tag_name: ${{ steps.tag_version.outputs.new_tag }}
+ release_name: Release ${{ steps.tag_version.outputs.new_tag }}
+
+ - name: Set Release URL
+ id: set_release_url
+ run: echo "::set-output name=release_url::${{ steps.create_release.outputs.upload_url }}"
+
+ - 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
+ if: ${{ failure() }}
+ uses: appleboy/telegram-action@master
+ with:
+ to: ${{ secrets.TELEGRAM_CHAT }}
+ token: ${{ secrets.TELEGRAM_TOKEN }}
+ format: html
+ message: |
+ !!! FAILED !!!
+ Failed job: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
+
+
+ build:
+ name: Build packages
+ needs: release
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ include:
+ - os: windows-latest
+ TARGET: windows
+ CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
+ OUT_FILE_NAME: butler.exe
+ ASSET_MIME: application/vnd.microsoft.portable-executable
+ - os: ubuntu-latest
+ TARGET: ubuntu
+ CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
+ OUT_FILE_NAME: butler
+ ASSET_MIME: application/x-binary
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Python 3.9
+ uses: actions/setup-python@v2
+ with:
+ python-version: 3.9
+
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install -r requirements.txt
+
+ - name: Build with pyinstaller for ${{ matrix.TARGET }}
+ run: ${{ matrix.CMD_BUILD }}
+
+ - name: Upload Artifacts
+ uses: actions/upload-artifact@v3
+ with:
+ name: ${{ matrix.OUT_FILE_NAME }}
+ path: ./dist/${{ matrix.OUT_FILE_NAME }}
+ retention-days: 1
+
+ - name: Upload Release Asset
+ id: upload-release-asset
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ needs.release.outputs.get_release_url }}
+ asset_path: ./dist/${{ matrix.OUT_FILE_NAME }}
+ asset_name: ${{ matrix.OUT_FILE_NAME }}
+ asset_content_type: ${{ matrix.ASSET_MIME }}
+
+ - name: Step To run on failure
+ if: ${{ failure() }}
+ uses: appleboy/telegram-action@master
+ with:
+ to: ${{ secrets.TELEGRAM_CHAT }}
+ token: ${{ secrets.TELEGRAM_TOKEN }}
+ format: html
+ message: |
+ !!! FAILED !!!
+ Failed job: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
+
+
+ telegram:
+ runs-on: ubuntu-latest
+ name: Notification
+ needs: [ release, build ]
+
+ steps:
+ - name: Notify telegram message after Released
+ uses: appleboy/telegram-action@master
+ with:
+ to: ${{ secrets.TELEGRAM_CHAT }}
+ token: ${{ secrets.TELEGRAM_TOKEN }}
+ format: html
+ message: |
+ ${{ github.actor }} created commit:
+
+ WorkFlows: ActionsList
+
+ Commit with tag: ${{ needs.release.outputs.get_current_tag }}
+
+ Repository: ${{ github.repository }}
+
+ Branch: ${{ github.ref }}
+
+ Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ needs.release.outputs.get_current_tag }}
+
+ See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index e23ba1f..26e10b3 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -2,7 +2,7 @@ name: CI
on:
push:
- branches: [ main ]
+ branches: [ develop ]
jobs:
code_quality:
@@ -27,39 +27,6 @@ jobs:
run:
isort --check .
-
- release:
- name: Create Release
- runs-on: ubuntu-latest
- needs: code_quality
- outputs:
- 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: Bump version and push tag
- id: tag_version
- uses: mathieudutour/github-tag-action@v6.0
- with:
- github_token: ${{ secrets.REPOS_TOKEN }}
-
- - name: Create Release
- id: create_release
- uses: actions/create-release@v1
- env:
- GITHUB_TOKEN: ${{ secrets.REPOS_TOKEN }}
- with:
- tag_name: ${{ steps.tag_version.outputs.new_tag }}
- release_name: Release ${{ steps.tag_version.outputs.new_tag }}
-
- - name: Set Release URL
- id: set_release_url
- run: echo "::set-output name=release_url::${{ steps.create_release.outputs.upload_url }}"
-
- - 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
if: ${{ failure() }}
uses: appleboy/telegram-action@master
@@ -71,93 +38,3 @@ jobs:
!!! FAILED !!!
Failed job: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
-
-
- build:
- name: Build packages
- needs: release
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- include:
- - os: windows-latest
- TARGET: windows
- CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
- OUT_FILE_NAME: butler.exe
- ASSET_MIME: application/vnd.microsoft.portable-executable
- - os: ubuntu-latest
- TARGET: ubuntu
- CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
- OUT_FILE_NAME: butler
- ASSET_MIME: application/x-binary
-
- steps:
- - uses: actions/checkout@v2
- - name: Set up Python 3.9
- uses: actions/setup-python@v2
- with:
- python-version: 3.9
-
- - name: Install dependencies
- run: |
- python -m pip install --upgrade pip
- pip install -r requirements.txt
- - name: Build with pyinstaller for ${{ matrix.TARGET }}
- run: ${{ matrix.CMD_BUILD }}
-
- - uses: actions/upload-artifact@v3
- with:
- name: ${{ matrix.OUT_FILE_NAME }}
- path: ./dist/${{ matrix.OUT_FILE_NAME }}
- retention-days: 1
-
- - name: Upload Release Asset
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ needs.release.outputs.get_release_url }}
- asset_path: ./dist/${{ matrix.OUT_FILE_NAME }}
- asset_name: ${{ matrix.OUT_FILE_NAME }}
- asset_content_type: ${{ matrix.ASSET_MIME }}
-
- - name: Step To run on failure
- if: ${{ failure() }}
- uses: appleboy/telegram-action@master
- with:
- to: ${{ secrets.TELEGRAM_CHAT }}
- token: ${{ secrets.TELEGRAM_TOKEN }}
- format: html
- message: |
- !!! FAILED !!!
- Failed job: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
-
-
- telegram:
- runs-on: ubuntu-latest
- name: Notification
- needs: [ release, build ]
-
- steps:
- - name: Notify telegram message after Released
- uses: appleboy/telegram-action@master
- with:
- to: ${{ secrets.TELEGRAM_CHAT }}
- token: ${{ secrets.TELEGRAM_TOKEN }}
- format: html
- message: |
- ${{ github.actor }} created commit:
-
- WorkFlows: ActionsList
-
- Commit with tag: ${{ needs.release.outputs.get_current_tag }}
-
- Repository: ${{ github.repository }}
-
- Branch: ${{ github.ref }}
-
- Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ needs.release.outputs.get_current_tag }}
-
- See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
diff --git a/butler.py b/butler.py
index f7df3c8..2bd6ddf 100644
--- a/butler.py
+++ b/butler.py
@@ -25,10 +25,13 @@
def clean_the_dir(directory_path):
for files in os.listdir(directory_path):
path = os.path.join(directory_path, files)
- try:
- shutil.rmtree(path)
- except OSError:
- os.remove(path)
+ if files == os.path.basename(__file__):
+ pass
+ else:
+ try:
+ shutil.rmtree(path)
+ except OSError:
+ os.remove(path)
def group_up_files(new_dir_name):
From 50aac7f5c126c6a23b397c74eb0092e81c53cad5 Mon Sep 17 00:00:00 2001
From: CoolCoderCarl <123qwekir2wl@gmail.com>
Date: Thu, 12 May 2022 18:54:17 +0300
Subject: [PATCH 2/6] Update build.yaml & add release.yaml
---
.github/workflows/build.yaml | 74 ++++-------------
.github/workflows/release.yaml | 142 +++++++++++++++++++++++++++++++++
2 files changed, 156 insertions(+), 60 deletions(-)
create mode 100644 .github/workflows/release.yaml
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index eef5c9a..90491d0 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -1,59 +1,16 @@
name: CI
on:
- push:
+ pull_request:
branches: [ main ]
jobs:
- release:
- name: Create Release
- runs-on: ubuntu-latest
- outputs:
- 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: Bump version and push tag
- id: tag_version
- uses: mathieudutour/github-tag-action@v6.0
- with:
- github_token: ${{ secrets.REPOS_TOKEN }}
-
- - name: Create Release
- id: create_release
- uses: actions/create-release@v1
- env:
- GITHUB_TOKEN: ${{ secrets.REPOS_TOKEN }}
- with:
- tag_name: ${{ steps.tag_version.outputs.new_tag }}
- release_name: Release ${{ steps.tag_version.outputs.new_tag }}
-
- - name: Set Release URL
- id: set_release_url
- run: echo "::set-output name=release_url::${{ steps.create_release.outputs.upload_url }}"
-
- - 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
- if: ${{ failure() }}
- uses: appleboy/telegram-action@master
- with:
- to: ${{ secrets.TELEGRAM_CHAT }}
- token: ${{ secrets.TELEGRAM_TOKEN }}
- format: html
- message: |
- !!! FAILED !!!
- Failed job: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
-
-
build:
name: Build packages
- needs: release
runs-on: ${{ matrix.os }}
+ outputs:
+ get_current_tag: ${{ steps.set_current_tag_id.outputs.current_tag }}
strategy:
matrix:
include:
@@ -70,6 +27,12 @@ jobs:
steps:
- uses: actions/checkout@v2
+ - name: Bump version and push tag
+ id: tag_version
+ uses: mathieudutour/github-tag-action@v6.0
+ with:
+ github_token: ${{ secrets.REPOS_TOKEN }}
+
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
@@ -90,16 +53,9 @@ jobs:
path: ./dist/${{ matrix.OUT_FILE_NAME }}
retention-days: 1
- - name: Upload Release Asset
- id: upload-release-asset
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ needs.release.outputs.get_release_url }}
- asset_path: ./dist/${{ matrix.OUT_FILE_NAME }}
- asset_name: ${{ matrix.OUT_FILE_NAME }}
- asset_content_type: ${{ matrix.ASSET_MIME }}
+ - 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
if: ${{ failure() }}
@@ -117,7 +73,7 @@ jobs:
telegram:
runs-on: ubuntu-latest
name: Notification
- needs: [ release, build ]
+ needs: [ build ]
steps:
- name: Notify telegram message after Released
@@ -131,12 +87,10 @@ jobs:
WorkFlows: ActionsList
- Commit with tag: ${{ needs.release.outputs.get_current_tag }}
+ Commit with tag: ${{ needs.build.outputs.get_current_tag }}
Repository: ${{ github.repository }}
Branch: ${{ github.ref }}
- Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ needs.release.outputs.get_current_tag }}
-
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
new file mode 100644
index 0000000..eef5c9a
--- /dev/null
+++ b/.github/workflows/release.yaml
@@ -0,0 +1,142 @@
+name: CI
+
+on:
+ push:
+ branches: [ main ]
+
+jobs:
+
+ release:
+ name: Create Release
+ runs-on: ubuntu-latest
+ outputs:
+ 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: Bump version and push tag
+ id: tag_version
+ uses: mathieudutour/github-tag-action@v6.0
+ with:
+ github_token: ${{ secrets.REPOS_TOKEN }}
+
+ - name: Create Release
+ id: create_release
+ uses: actions/create-release@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.REPOS_TOKEN }}
+ with:
+ tag_name: ${{ steps.tag_version.outputs.new_tag }}
+ release_name: Release ${{ steps.tag_version.outputs.new_tag }}
+
+ - name: Set Release URL
+ id: set_release_url
+ run: echo "::set-output name=release_url::${{ steps.create_release.outputs.upload_url }}"
+
+ - 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
+ if: ${{ failure() }}
+ uses: appleboy/telegram-action@master
+ with:
+ to: ${{ secrets.TELEGRAM_CHAT }}
+ token: ${{ secrets.TELEGRAM_TOKEN }}
+ format: html
+ message: |
+ !!! FAILED !!!
+ Failed job: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
+
+
+ build:
+ name: Build packages
+ needs: release
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ include:
+ - os: windows-latest
+ TARGET: windows
+ CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
+ OUT_FILE_NAME: butler.exe
+ ASSET_MIME: application/vnd.microsoft.portable-executable
+ - os: ubuntu-latest
+ TARGET: ubuntu
+ CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
+ OUT_FILE_NAME: butler
+ ASSET_MIME: application/x-binary
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Python 3.9
+ uses: actions/setup-python@v2
+ with:
+ python-version: 3.9
+
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install -r requirements.txt
+
+ - name: Build with pyinstaller for ${{ matrix.TARGET }}
+ run: ${{ matrix.CMD_BUILD }}
+
+ - name: Upload Artifacts
+ uses: actions/upload-artifact@v3
+ with:
+ name: ${{ matrix.OUT_FILE_NAME }}
+ path: ./dist/${{ matrix.OUT_FILE_NAME }}
+ retention-days: 1
+
+ - name: Upload Release Asset
+ id: upload-release-asset
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ needs.release.outputs.get_release_url }}
+ asset_path: ./dist/${{ matrix.OUT_FILE_NAME }}
+ asset_name: ${{ matrix.OUT_FILE_NAME }}
+ asset_content_type: ${{ matrix.ASSET_MIME }}
+
+ - name: Step To run on failure
+ if: ${{ failure() }}
+ uses: appleboy/telegram-action@master
+ with:
+ to: ${{ secrets.TELEGRAM_CHAT }}
+ token: ${{ secrets.TELEGRAM_TOKEN }}
+ format: html
+ message: |
+ !!! FAILED !!!
+ Failed job: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
+
+
+ telegram:
+ runs-on: ubuntu-latest
+ name: Notification
+ needs: [ release, build ]
+
+ steps:
+ - name: Notify telegram message after Released
+ uses: appleboy/telegram-action@master
+ with:
+ to: ${{ secrets.TELEGRAM_CHAT }}
+ token: ${{ secrets.TELEGRAM_TOKEN }}
+ format: html
+ message: |
+ ${{ github.actor }} created commit:
+
+ WorkFlows: ActionsList
+
+ Commit with tag: ${{ needs.release.outputs.get_current_tag }}
+
+ Repository: ${{ github.repository }}
+
+ Branch: ${{ github.ref }}
+
+ Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ needs.release.outputs.get_current_tag }}
+
+ See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
From 39c0cc77783a31ce9155655dde52c5e7a4b8bc87 Mon Sep 17 00:00:00 2001
From: CoolCoderCarl <123qwekir2wl@gmail.com>
Date: Thu, 12 May 2022 19:37:44 +0300
Subject: [PATCH 3/6] Update build.yaml & butler.py
---
.github/workflows/build.yaml | 4 +++-
butler.py | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 90491d0..c7e3ced 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -76,7 +76,7 @@ jobs:
needs: [ build ]
steps:
- - name: Notify telegram message after Released
+ - name: Notify telegram message after Packaging
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT }}
@@ -93,4 +93,6 @@ jobs:
Branch: ${{ github.ref }}
+ Artifacts: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
+
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
diff --git a/butler.py b/butler.py
index 2bd6ddf..5931b4f 100644
--- a/butler.py
+++ b/butler.py
@@ -25,8 +25,8 @@
def clean_the_dir(directory_path):
for files in os.listdir(directory_path):
path = os.path.join(directory_path, files)
- if files == os.path.basename(__file__):
- pass
+ if os.path.basename(__file__) == (path.split("/")[-1]):
+ print("Skipped " + path.split("/")[-1])
else:
try:
shutil.rmtree(path)
From 9a5f48d3eb9a3202396977f0ddd6c5ac021d06ec Mon Sep 17 00:00:00 2001
From: CoolCoderCarl <123qwekir2wl@gmail.com>
Date: Thu, 12 May 2022 19:54:41 +0300
Subject: [PATCH 4/6] Update butler.py
---
butler.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/butler.py b/butler.py
index 5931b4f..3164f57 100644
--- a/butler.py
+++ b/butler.py
@@ -25,7 +25,8 @@
def clean_the_dir(directory_path):
for files in os.listdir(directory_path):
path = os.path.join(directory_path, files)
- if os.path.basename(__file__) == (path.split("/")[-1]):
+ print(path.split("/")[-1])
+ if "butler" in (path.split("/")[-1]):
print("Skipped " + path.split("/")[-1])
else:
try:
From ee453b4c88fad4ca05c0c459dc568158e0d68e6a Mon Sep 17 00:00:00 2001
From: CoolCoderCarl <123qwekir2wl@gmail.com>
Date: Thu, 12 May 2022 23:14:21 +0300
Subject: [PATCH 5/6] Update butler.py
---
butler.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/butler.py b/butler.py
index 3164f57..4bd45a3 100644
--- a/butler.py
+++ b/butler.py
@@ -8,6 +8,7 @@
".docx",
".pdf",
".xlsx",
+ ".zip",
".bmp",
".jpg",
".rtf",
@@ -25,7 +26,6 @@
def clean_the_dir(directory_path):
for files in os.listdir(directory_path):
path = os.path.join(directory_path, files)
- print(path.split("/")[-1])
if "butler" in (path.split("/")[-1]):
print("Skipped " + path.split("/")[-1])
else:
@@ -57,7 +57,6 @@ def group_up_files(new_dir_name):
epilog="""(c) CoolCoderCarl""",
)
-
parser.add_argument(
"--clean", help="Clean target directory. Example /tmp/, both slash required"
)
From a4def01bc35b9d9e2fda013b155eefbd5650fef8 Mon Sep 17 00:00:00 2001
From: CoolCoderCarl <123qwekir2wl@gmail.com>
Date: Tue, 17 May 2022 13:36:05 +0300
Subject: [PATCH 6/6] Add zip function
---
.../workflows/{ci.yaml => code_quality.yaml} | 2 +-
butler.py | 28 +++++++++++++++++--
2 files changed, 27 insertions(+), 3 deletions(-)
rename .github/workflows/{ci.yaml => code_quality.yaml} (98%)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/code_quality.yaml
similarity index 98%
rename from .github/workflows/ci.yaml
rename to .github/workflows/code_quality.yaml
index 26e10b3..785a55b 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/code_quality.yaml
@@ -1,4 +1,4 @@
-name: CI
+name: Code Quality
on:
push:
diff --git a/butler.py b/butler.py
index 4bd45a3..0856ff9 100644
--- a/butler.py
+++ b/butler.py
@@ -1,6 +1,9 @@
import argparse
import os
import shutil
+from datetime import datetime
+from os.path import basename
+from zipfile import ZipFile
files_extension = [
".txt",
@@ -23,7 +26,7 @@
target_dir_name = "ALL"
-def clean_the_dir(directory_path):
+def clean_the_dir(directory_path: str):
for files in os.listdir(directory_path):
path = os.path.join(directory_path, files)
if "butler" in (path.split("/")[-1]):
@@ -35,7 +38,7 @@ def clean_the_dir(directory_path):
os.remove(path)
-def group_up_files(new_dir_name):
+def group_up_files(new_dir_name: str):
print(new_dir_name)
for file in os.listdir(args.dir):
for ext in files_extension:
@@ -51,6 +54,19 @@ def group_up_files(new_dir_name):
shutil.move(file_path, new_dir_path)
+def create_archive(dir_to_archive: str):
+ 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 ".zip" in filename:
+ pass
+ else:
+ zip_path = os.path.join(folder_name, filename)
+ zip_obj.write(zip_path, basename(zip_path))
+
+
parser = argparse.ArgumentParser(
prog="butler",
description="""The Butler helps keep the castle clean and tidy""",
@@ -64,6 +80,12 @@ def group_up_files(new_dir_name):
parser.add_argument(
"--dir", help="Dir to group up the files. Example /tmp/, both slash required"
)
+
+parser.add_argument(
+ "--archive",
+ help="Create archive from target directory. Example /tmp/, both slash required",
+)
+
args = parser.parse_args()
@@ -72,3 +94,5 @@ def group_up_files(new_dir_name):
clean_the_dir(args.clean)
elif args.dir:
group_up_files(target_dir_name)
+ elif args.archive:
+ create_archive(args.archive)