diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 221f9d3..20a1186 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 @@ -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: @@ -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: @@ -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: 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..8033a0e 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", @@ -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: @@ -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: @@ -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: @@ -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)