Skip to content

Commit

Permalink
Merge pull request #85 from Drazzilb08/patch-1
Browse files Browse the repository at this point in the history
Patch 1
  • Loading branch information
Drazzilb08 authored Feb 17, 2024
2 parents 2b56f54 + 54dc09d commit 06862d6
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 400 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ name: Docker Develop Release
on:
push:
branches: [ dev ]
paths-ignore:
- '**/README.md'
# Ignore updates to .github
- '**/.github/**'
pull_request:
branches: [ dev ]

jobs:

docker-latest:
docker-dev:
runs-on: ubuntu-latest

steps:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Docker Latest Release
on:
push:
branches: [ master ]
paths-ignore:
- '**/README.md'
# Ignore updates to .github
- '**/.github/**'

jobs:

Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Docker Patch Release

on:
push:
branches:
- patch-*
paths-ignore:
- '**/README.md'
# Ignore updates to .github
- '**/.github/**'
pull_request:
branches:
- patch-*

jobs:
docker-patch:
runs-on: ubuntu-latest
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- uses: actions/checkout@v4
- name: checkout the repo
run: |
docker login --username ${{ secrets.GH_USERNAME }} --password ${{ secrets.GH_TOKEN }} ghcr.io
docker build --build-arg BRANCH=$(git rev-parse --abbrev-ref HEAD) -t ghcr.io/drazzilb08/userscripts:${{ steps.extract_branch.outputs.branch }} .
docker push ghcr.io/drazzilb08/userscripts:${{ steps.extract_branch.outputs.branch }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
build-args: |
"BRANCH=${{ steps.extract_branch.outputs.branch }}"
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/userscripts:${{ steps.extract_branch.outputs.branch }}
3 changes: 2 additions & 1 deletion .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ on:
tags:
- v*


jobs:

docker-latest:
docker-version:
runs-on: ubuntu-latest

steps:
Expand Down
3 changes: 0 additions & 3 deletions config/config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ border_replacerr:
# Colors: https://www.w3schools.com/colors/colors_picker.asp
log_level: info
dry_run: true
asset_folders: false
source_dirs:
- /path/to/posters/
destination_dir: /path/to/output/
Expand Down Expand Up @@ -327,7 +326,6 @@ border_replacerr:

unmatched_assets:
log_level: info
asset_folders: false
instances:
- plex_1
- radarr_1
Expand Down Expand Up @@ -369,7 +367,6 @@ unmatched_assets:
poster_cleanarr:
log_level: info
dry_run: true
asset_folders: true
instances:
- plex_1
- radarr_1
Expand Down
63 changes: 35 additions & 28 deletions modules/border_replacerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,9 @@ def copy_files(assets_dict, destination_dir, dry_run):
Copies the files in the input directory to the output directory.
Args:
source_dirs (str): The input directory.
assets_dict (dict): The dictionary of assets.
destination_dir (str): The output directory.
asset_folders (bool): Whether to use asset folders.
dry_run (bool): Whether to perform a dry run.
Returns:
None
"""
Expand Down Expand Up @@ -380,10 +378,8 @@ def copy_files(assets_dict, destination_dir, dry_run):
if not dry_run:
if not os.path.exists(output_path):
os.makedirs(output_path)
else:
output_path = destination_dir
else:
logger.debug(f"Creating {output_path}")
logger.debug(f"Would have created {output_path}")
else:
output_path = destination_dir

Expand All @@ -399,48 +395,72 @@ def copy_files(assets_dict, destination_dir, dry_run):
if not dry_run:
if os.path.isfile(final_path):
if not filecmp.cmp(final_path, input_file):
shutil.copy(input_file, final_path)
try:
shutil.copy(input_file, final_path)
except shutil.SameFileError:
logger.debug(f"Input file {input_file} is the same as {final_path}, skipping")
logger.debug(f"Input file {input_file} is different from {final_path}, copying to {output_basename}")
messages.append(f"Copied {data['title']}{year} - {file_name} to {output_basename}")
else:
shutil.copy(input_file, final_path)
try:
shutil.copy(input_file, final_path)
except shutil.SameFileError:
logger.debug(f"Input file {input_file} is the same as {final_path}, skipping")
logger.debug(f"Input file {input_file} does not exist in {output_path}, copying to {output_basename}")
messages.append(f"Copied {data['title']}{year} - {file_name} to {output_basename}")
else:
messages.append(f"Would have copied {data['title']}{year} - {file_name} to {output_basename}")
return messages

def process_files(source_dirs, destination_dir, asset_folders, dry_run):
def process_files(source_dirs, destination_dir, dry_run):
"""
Processes the files in the input directory.
Args:
source_dirs (str): The input directory.
destination_dir (str): The output directory.
asset_folders (bool): Whether to use asset folders.
Returns:
None
"""

# Obtain script configuration details
script_config = config.script_config
schedule = script_config['schedule']
border_colors = script_config['border_colors']
skip = script_config['skip']
schedule = script_config.get('schedule', None)
border_colors = script_config.get('border_colors', None)
skip = script_config.get('skip', False)

# Convert single string border color to a list if necessary
border_colors = [border_colors] if isinstance(border_colors, str) else border_colors
source_dirs = [source_dirs] if isinstance(source_dirs, str) else source_dirs

table = [
["Script Settings"],
]
logger.debug(create_table(table))
logger.debug(f'{"Dry_run:":<20}{config.dry_run}')
logger.debug(f'{"Log Level:":<20}{config.log_level}')
logger.debug(f'{"Input Dir:":<20}{source_dirs}')
logger.debug(f'{"Output Dir:":<20}{destination_dir}')
logger.debug(f'{"Border Colors:":<20}{border_colors}')
logger.debug(f'{"Skip:":<20}{skip}')
logger.debug(f'{"Schedule:":<20}{schedule}')
logger.debug(create_bar("-"))

run_holiday = False

# Check for a scheduled event to update border colors if provided
if schedule:
border_colors, run_holiday, holiday = check_holiday(schedule, border_colors)

if not os.path.exists(destination_dir):
logger.error(f"Output directory {destination_dir} does not exist.")
return

assets_list = []
# Categorize files in the input directory into assets
for path in source_dirs:
results = categorize_files(path, asset_folders)
results = categorize_files(path)
if results:
assets_list.extend(results)
else:
Expand Down Expand Up @@ -513,29 +533,16 @@ def main():
destination_dir = script_config['destination_dir']
schedule = script_config['schedule']
border_colors = script_config['border_colors']
asset_folders = script_config['asset_folders']
dry_run = config.dry_run

# Convert single string border color to a list if necessary
if isinstance(border_colors, str):
border_colors = [border_colors]

# Creating a table to log script settings in debug mode
table = [
["Script Settings"],
]
logger.debug(create_table(table))
logger.debug(f'{"Dry_run:":<20}{config.dry_run}')
logger.debug(f'{"Log Level:":<20}{config.log_level}')
logger.debug(f'{"Input Dir:":<20}{source_dirs}')
logger.debug(f'{"Output Dir:":<20}{destination_dir}')
logger.debug(f'{"Schedule:":<20}{schedule}')
logger.debug(create_bar("-"))

# Process files in the input directory with specified settings
process_files(source_dirs, destination_dir, asset_folders, dry_run)
process_files(source_dirs, destination_dir, dry_run)

logger.info(f"Border Replacer Complete") # Log completion message
except KeyboardInterrupt:
print("Keyboard Interrupt detected. Exiting...")
sys.exit()
Expand Down
Loading

0 comments on commit 06862d6

Please sign in to comment.