Skip to content

Commit

Permalink
Merge pull request #1504 from clinton-hall/hotfix/sourcecleaner
Browse files Browse the repository at this point in the history
Hotfix/sourcecleaner
  • Loading branch information
labrys authored Jan 6, 2019
2 parents e386eaa + 6616801 commit b86693e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 12.0.2
current_version = 12.0.3
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nzbToMedia v12.0.2
nzbToMedia v12.0.3
==================

Provides an [efficient](https://github.com/clinton-hall/nzbToMedia/wiki/Efficient-on-demand-post-processing) way to handle postprocessing for [CouchPotatoServer](https://couchpota.to/ "CouchPotatoServer") and [SickBeard](http://sickbeard.com/ "SickBeard") (and its [forks](https://github.com/clinton-hall/nzbToMedia/wiki/Failed-Download-Handling-%28FDH%29#sick-beard-and-its-forks))
Expand Down
45 changes: 41 additions & 4 deletions cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
import os
import subprocess
import sys
import shutil

FOLDER_STRUCTURE = {
'libs': [
'common',
'custom',
'py2',
'win',
],
'core': [
'auto_process',
'extractor',
],
}


class WorkingDirectory(object):
Expand Down Expand Up @@ -106,7 +120,22 @@ def clean_folders(*paths):
return result


def clean(*paths):
def force_clean_folder(path, required):
root, dirs, files = next(os.walk(path))
required = sorted(required)
if required:
print('Skipping required subfolders', required)
remove = sorted(set(dirs).difference(required))
missing = sorted(set(required).difference(dirs))
for path in remove:
pathname = os.path.join(root, path)
print('Removing', pathname)
shutil.rmtree(pathname)
if missing:
raise Exception('Required subfolders missing:', missing)


def clean(paths):
"""Clean up bytecode and obsolete folders."""
with WorkingDirectory(module_path()) as cwd:
if cwd.working_directory != cwd.original_directory:
Expand All @@ -121,15 +150,23 @@ def clean(*paths):
print(result or 'No bytecode to clean')

if paths and os.path.exists('.git'):
print('\n-- Cleaning folders: {} --'.format(paths))
print('\n-- Cleaning folders: {} --'.format(list(paths)))
try:
result = clean_folders(*paths)
except SystemExit as error:
print(error)
else:
print(result or 'No folders to clean\n')
else:
print('Directory is not a git repository')
print('\nDirectory is not a git repository')
try:
items = paths.items()
except AttributeError:
print('Failed to clean, no subfolder structure given')
else:
for folder, subfolders in items:
print('\nForce cleaning folder:', folder)
force_clean_folder(folder, subfolders)

if cwd.working_directory != cwd.original_directory:
print('Returning to directory: ', cwd.original_directory)
Expand All @@ -138,4 +175,4 @@ def clean(*paths):


if __name__ == '__main__':
clean('libs', 'core')
clean(FOLDER_STRUCTURE)
2 changes: 1 addition & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
resume_torrent, remove_dir, remove_read_only, sanitize_name, update_download_info_status,
)

__version__ = '12.0.2'
__version__ = '12.0.3'

# Client Agents
NZB_CLIENTS = ['sabnzbd', 'nzbget', 'manual']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def read(*names, **kwargs):

setup(
name='nzbToMedia',
version='12.0.2',
version='12.0.3',
license='GPLv3',
description='Efficient on demand post processing',
long_description="""
Expand Down

0 comments on commit b86693e

Please sign in to comment.