From 7300c2ecbca98b58fc80f64af1b7b3b777f8f15b Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Sat, 21 May 2022 00:47:31 +0300 Subject: [PATCH 1/4] Update flow & butler.py --- .github/workflows/build.yaml | 20 +++++++++++---- .github/workflows/code_quality.yaml | 13 ++++------ .github/workflows/ignore.yaml | 38 +++++++++++++++++++++++++++++ .github/workflows/release.yaml | 15 +++++++++--- butler.py | 24 ++++++++++++++++-- 5 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/ignore.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 221f9d3..a774ed6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,7 +2,11 @@ name: Build on: pull_request: - branches: [ main ] + branches: [ develop ] + paths-ignore: + - 'README.md' + - '.gitignore' + - 'changelog.json' jobs: @@ -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 @@ -28,7 +35,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: @@ -58,7 +65,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: @@ -79,7 +89,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: diff --git a/.github/workflows/code_quality.yaml b/.github/workflows/code_quality.yaml index 637c176..a0ffdb1 100644 --- a/.github/workflows/code_quality.yaml +++ b/.github/workflows/code_quality.yaml @@ -2,7 +2,7 @@ name: Code Quality on: push: - branches: [ develop ] + branches: [ feature/* ] jobs: code_quality: @@ -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: diff --git a/.github/workflows/ignore.yaml b/.github/workflows/ignore.yaml new file mode 100644 index 0000000..51c5f71 --- /dev/null +++ b/.github/workflows/ignore.yaml @@ -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: + + WorkFlows: ActionsList + + Repository: ${{ github.repository }} + + Branch: ${{ github.ref }} + + Something were changed + + See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }} \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index eb3ccc9..0f95b41 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,8 +1,12 @@ name: Release on: - push: + pull_request: branches: [ main ] + paths-ignore: + - 'README.md' + - '.gitignore' + - 'changelog.json' jobs: @@ -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 @@ -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: @@ -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: diff --git a/butler.py b/butler.py index c92d1ea..6276f1f 100644 --- a/butler.py +++ b/butler.py @@ -8,6 +8,7 @@ files_extension = [ ".txt", ".ini", + ".md", ".doc", ".docx", ".rtf", @@ -24,6 +25,7 @@ ".iso", ".mkv", ".mov", + ".mp4", ".bmp", ".jpg", ".png", @@ -44,13 +46,18 @@ # 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: @@ -60,12 +67,19 @@ def clean_the_dir(path_to_clean: str): def group_up_files(new_dir_name: str): + """ + 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.dir == "/": 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: + if "butler" in filename.lower(): print("Skipped " + filename) else: for ext in files_extension: @@ -83,6 +97,12 @@ 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: From 47af831cc14a6ee15fa05bf41a42ca129c8fac78 Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Sat, 21 May 2022 01:55:43 +0300 Subject: [PATCH 2/4] Add subparser for group_up_files method --- butler.py | 55 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/butler.py b/butler.py index 6276f1f..65a9ba9 100644 --- a/butler.py +++ b/butler.py @@ -41,8 +41,6 @@ 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): @@ -74,21 +72,23 @@ def group_up_files(new_dir_name: str): :param new_dir_name: :return: """ - if args.dir == "/": + if args.source == "/": print("It is totally not great idea to modify all things") exit(1) else: - for filename in os.listdir(args.dir): + 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: @@ -108,7 +108,7 @@ def create_archive(dir_to_archive: str): 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: @@ -118,32 +118,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) From 981dbd46a9d2f96c6cc992f76d657838ca7ad29e Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Sat, 21 May 2022 02:01:01 +0300 Subject: [PATCH 3/4] Update build.yaml --- .github/workflows/build.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a774ed6..20a1186 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -31,6 +31,11 @@ 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 }}" From 5844559829d04ffa80cc4c38fd05e5a3ee5813ac Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Sat, 21 May 2022 02:05:44 +0300 Subject: [PATCH 4/4] Update butler.py --- butler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/butler.py b/butler.py index 65a9ba9..8033a0e 100644 --- a/butler.py +++ b/butler.py @@ -42,7 +42,6 @@ archives_extension = [".zip", ".7z", ".gz", ".bz", ".gzip", ".bzip", ".iso"] -# Delete files by mask or exclude deletion def clean_the_dir(path_to_clean: str): """ Clean the target directory, but not delete directory itself