mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 05:43:16 -07:00
Merge pull request #1440 from clinton-hall/fix/bytecode
Clean up bytecode left over after update
This commit is contained in:
commit
cbc8655b9a
7 changed files with 73 additions and 27 deletions
|
@ -23,20 +23,21 @@ except ImportError:
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
sys.ext('Please install pywin32')
|
sys.ext('Please install pywin32')
|
||||||
|
|
||||||
PROGRAM_DIR = libs.util.module_root()
|
APP_ROOT = libs.util.module_path(parent=True)
|
||||||
|
SOURCE_ROOT = libs.util.module_path()
|
||||||
|
|
||||||
# init preliminaries
|
# init preliminaries
|
||||||
SYS_ARGV = sys.argv[1:]
|
SYS_ARGV = sys.argv[1:]
|
||||||
APP_FILENAME = sys.argv[0]
|
APP_FILENAME = sys.argv[0]
|
||||||
APP_NAME = os.path.basename(APP_FILENAME)
|
APP_NAME = os.path.basename(APP_FILENAME)
|
||||||
LOG_DIR = os.path.join(PROGRAM_DIR, 'logs')
|
LOG_DIR = os.path.join(APP_ROOT, 'logs')
|
||||||
LOG_FILE = os.path.join(LOG_DIR, 'nzbtomedia.log')
|
LOG_FILE = os.path.join(LOG_DIR, 'nzbtomedia.log')
|
||||||
PID_FILE = os.path.join(LOG_DIR, 'nzbtomedia.pid')
|
PID_FILE = os.path.join(LOG_DIR, 'nzbtomedia.pid')
|
||||||
CONFIG_FILE = os.path.join(PROGRAM_DIR, 'autoProcessMedia.cfg')
|
CONFIG_FILE = os.path.join(APP_ROOT, 'autoProcessMedia.cfg')
|
||||||
CONFIG_SPEC_FILE = os.path.join(PROGRAM_DIR, 'autoProcessMedia.cfg.spec')
|
CONFIG_SPEC_FILE = os.path.join(APP_ROOT, 'autoProcessMedia.cfg.spec')
|
||||||
CONFIG_MOVIE_FILE = os.path.join(PROGRAM_DIR, 'autoProcessMovie.cfg')
|
CONFIG_MOVIE_FILE = os.path.join(APP_ROOT, 'autoProcessMovie.cfg')
|
||||||
CONFIG_TV_FILE = os.path.join(PROGRAM_DIR, 'autoProcessTv.cfg')
|
CONFIG_TV_FILE = os.path.join(APP_ROOT, 'autoProcessTv.cfg')
|
||||||
TEST_FILE = os.path.join(PROGRAM_DIR, 'tests', 'test.mp4')
|
TEST_FILE = os.path.join(APP_ROOT, 'tests', 'test.mp4')
|
||||||
MYAPP = None
|
MYAPP = None
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
@ -747,7 +748,7 @@ def initialize(section=None):
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg.exe')
|
FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg.exe')
|
||||||
FFPROBE = os.path.join(FFMPEG_PATH, 'ffprobe.exe')
|
FFPROBE = os.path.join(FFMPEG_PATH, 'ffprobe.exe')
|
||||||
SEVENZIP = os.path.join(PROGRAM_DIR, 'core', 'extractor', 'bin', platform.machine(), '7z.exe')
|
SEVENZIP = os.path.join(APP_ROOT, 'core', 'extractor', 'bin', platform.machine(), '7z.exe')
|
||||||
SHOWEXTRACT = int(str(CFG["Windows"]["show_extraction"]), 0)
|
SHOWEXTRACT = int(str(CFG["Windows"]["show_extraction"]), 0)
|
||||||
|
|
||||||
if not (os.path.isfile(FFMPEG)): # problem
|
if not (os.path.isfile(FFMPEG)): # problem
|
||||||
|
|
|
@ -19,7 +19,7 @@ def extract(file_path, output_destination):
|
||||||
core.logger.error("EXTRACTOR: Could not find 7-zip, Exiting")
|
core.logger.error("EXTRACTOR: Could not find 7-zip, Exiting")
|
||||||
return False
|
return False
|
||||||
wscriptlocation = os.path.join(os.environ['WINDIR'], 'system32', 'wscript.exe')
|
wscriptlocation = os.path.join(os.environ['WINDIR'], 'system32', 'wscript.exe')
|
||||||
invislocation = os.path.join(core.PROGRAM_DIR, 'core', 'extractor', 'bin', 'invisible.vbs')
|
invislocation = os.path.join(core.APP_ROOT, 'core', 'extractor', 'bin', 'invisible.vbs')
|
||||||
cmd_7zip = [wscriptlocation, invislocation, str(core.SHOWEXTRACT), core.SEVENZIP, "x", "-y"]
|
cmd_7zip = [wscriptlocation, invislocation, str(core.SHOWEXTRACT), core.SEVENZIP, "x", "-y"]
|
||||||
ext_7zip = [".rar", ".zip", ".tar.gz", "tgz", ".tar.bz2", ".tbz", ".tar.lzma", ".tlz", ".7z", ".xz"]
|
ext_7zip = [".rar", ".zip", ".tar.gz", "tgz", ".tar.bz2", ".tbz", ".tar.lzma", ".tlz", ".7z", ".xz"]
|
||||||
extract_commands = dict.fromkeys(ext_7zip, cmd_7zip)
|
extract_commands = dict.fromkeys(ext_7zip, cmd_7zip)
|
||||||
|
|
|
@ -22,7 +22,7 @@ def db_filename(filename="nzbtomedia.db", suffix=None):
|
||||||
"""
|
"""
|
||||||
if suffix:
|
if suffix:
|
||||||
filename = "{0}.{1}".format(filename, suffix)
|
filename = "{0}.{1}".format(filename, suffix)
|
||||||
return core.os.path.join(core.PROGRAM_DIR, filename)
|
return core.os.path.join(core.APP_ROOT, filename)
|
||||||
|
|
||||||
|
|
||||||
class DBConnection(object):
|
class DBConnection(object):
|
||||||
|
|
|
@ -15,6 +15,7 @@ from six.moves.urllib.request import urlretrieve
|
||||||
|
|
||||||
import core
|
import core
|
||||||
from core import github_api as github, logger
|
from core import github_api as github, logger
|
||||||
|
import libs.util
|
||||||
|
|
||||||
|
|
||||||
class CheckVersion(object):
|
class CheckVersion(object):
|
||||||
|
@ -48,7 +49,7 @@ class CheckVersion(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# check if we're a windows build
|
# check if we're a windows build
|
||||||
if os.path.isdir(os.path.join(core.PROGRAM_DIR, u'.git')):
|
if os.path.isdir(os.path.join(core.APP_ROOT, u'.git')):
|
||||||
install_type = 'git'
|
install_type = 'git'
|
||||||
else:
|
else:
|
||||||
install_type = 'source'
|
install_type = 'source'
|
||||||
|
@ -79,7 +80,23 @@ class CheckVersion(object):
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.updater.need_update():
|
if self.updater.need_update():
|
||||||
return self.updater.update()
|
result = self.updater.update()
|
||||||
|
self.clean()
|
||||||
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def clean():
|
||||||
|
# Clean libs
|
||||||
|
result = libs.util.git_clean(
|
||||||
|
remove_directories=True,
|
||||||
|
force=True,
|
||||||
|
ignore_rules=True,
|
||||||
|
paths=[
|
||||||
|
libs.LIB_ROOT,
|
||||||
|
core.SOURCE_ROOT,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
logger.debug(result)
|
||||||
|
|
||||||
|
|
||||||
class UpdateManager(object):
|
class UpdateManager(object):
|
||||||
|
@ -174,9 +191,9 @@ class GitUpdateManager(UpdateManager):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.log(u"Executing {cmd} with your shell in {directory}".format
|
logger.log(u"Executing {cmd} with your shell in {directory}".format
|
||||||
(cmd=cmd, directory=core.PROGRAM_DIR), logger.DEBUG)
|
(cmd=cmd, directory=core.APP_ROOT), logger.DEBUG)
|
||||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
shell=True, cwd=core.PROGRAM_DIR)
|
shell=True, cwd=core.APP_ROOT)
|
||||||
output, err = p.communicate()
|
output, err = p.communicate()
|
||||||
exit_status = p.returncode
|
exit_status = p.returncode
|
||||||
|
|
||||||
|
@ -345,7 +362,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
|
|
||||||
def _find_installed_version(self):
|
def _find_installed_version(self):
|
||||||
|
|
||||||
version_file = os.path.join(core.PROGRAM_DIR, u'version.txt')
|
version_file = os.path.join(core.APP_ROOT, u'version.txt')
|
||||||
|
|
||||||
if not os.path.isfile(version_file):
|
if not os.path.isfile(version_file):
|
||||||
self._cur_commit_hash = None
|
self._cur_commit_hash = None
|
||||||
|
@ -437,11 +454,11 @@ class SourceUpdateManager(UpdateManager):
|
||||||
"""
|
"""
|
||||||
tar_download_url = 'https://github.com/{org}/{repo}/tarball/{branch}'.format(
|
tar_download_url = 'https://github.com/{org}/{repo}/tarball/{branch}'.format(
|
||||||
org=self.github_repo_user, repo=self.github_repo, branch=self.branch)
|
org=self.github_repo_user, repo=self.github_repo, branch=self.branch)
|
||||||
version_path = os.path.join(core.PROGRAM_DIR, u'version.txt')
|
version_path = os.path.join(core.APP_ROOT, u'version.txt')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# prepare the update dir
|
# prepare the update dir
|
||||||
sb_update_dir = os.path.join(core.PROGRAM_DIR, u'sb-update')
|
sb_update_dir = os.path.join(core.APP_ROOT, u'sb-update')
|
||||||
|
|
||||||
if os.path.isdir(sb_update_dir):
|
if os.path.isdir(sb_update_dir):
|
||||||
logger.log(u"Clearing out update folder {dir} before extracting".format(dir=sb_update_dir))
|
logger.log(u"Clearing out update folder {dir} before extracting".format(dir=sb_update_dir))
|
||||||
|
@ -485,12 +502,12 @@ class SourceUpdateManager(UpdateManager):
|
||||||
|
|
||||||
# walk temp folder and move files to main folder
|
# walk temp folder and move files to main folder
|
||||||
logger.log(u"Moving files from {source} to {destination}".format
|
logger.log(u"Moving files from {source} to {destination}".format
|
||||||
(source=content_dir, destination=core.PROGRAM_DIR))
|
(source=content_dir, destination=core.APP_ROOT))
|
||||||
for dirname, dirnames, filenames in os.walk(content_dir): # @UnusedVariable
|
for dirname, dirnames, filenames in os.walk(content_dir): # @UnusedVariable
|
||||||
dirname = dirname[len(content_dir) + 1:]
|
dirname = dirname[len(content_dir) + 1:]
|
||||||
for curfile in filenames:
|
for curfile in filenames:
|
||||||
old_path = os.path.join(content_dir, dirname, curfile)
|
old_path = os.path.join(content_dir, dirname, curfile)
|
||||||
new_path = os.path.join(core.PROGRAM_DIR, dirname, curfile)
|
new_path = os.path.join(core.APP_ROOT, dirname, curfile)
|
||||||
|
|
||||||
# Avoid DLL access problem on WIN32/64
|
# Avoid DLL access problem on WIN32/64
|
||||||
# These files needing to be updated manually
|
# These files needing to be updated manually
|
||||||
|
|
|
@ -4,8 +4,7 @@ import sys
|
||||||
|
|
||||||
import libs.util
|
import libs.util
|
||||||
|
|
||||||
ROOT_DIR = libs.util.module_root()
|
LIB_ROOT = libs.util.module_path()
|
||||||
LIB_DIR = os.path.join(ROOT_DIR, 'libs')
|
|
||||||
|
|
||||||
COMMON = 'common'
|
COMMON = 'common'
|
||||||
CUSTOM = 'custom'
|
CUSTOM = 'custom'
|
||||||
|
@ -18,7 +17,7 @@ MANDATORY = {
|
||||||
CUSTOM,
|
CUSTOM,
|
||||||
}
|
}
|
||||||
DIRECTORY = {
|
DIRECTORY = {
|
||||||
lib: os.path.join(LIB_DIR, lib)
|
lib: os.path.join(LIB_ROOT, lib)
|
||||||
for lib in [COMMON, CUSTOM, PY2, WIN]
|
for lib in [COMMON, CUSTOM, PY2, WIN]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import time
|
||||||
import libs
|
import libs
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
os.chdir(libs.LIB_DIR)
|
os.chdir(libs.LIB_ROOT)
|
||||||
for lib, directory in libs.DIRECTORY.items():
|
for lib, directory in libs.DIRECTORY.items():
|
||||||
if lib == 'custom':
|
if lib == 'custom':
|
||||||
continue
|
continue
|
||||||
|
|
37
libs/util.py
37
libs/util.py
|
@ -4,19 +4,20 @@ import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'module_root',
|
'module_path',
|
||||||
'add_path',
|
'add_path',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def module_root(module=__file__):
|
def module_path(module=__file__, parent=False):
|
||||||
try:
|
try:
|
||||||
path = module.__file__
|
path = module.__file__
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
path = module
|
path = module
|
||||||
directory = os.path.dirname(path)
|
directory = os.path.dirname(path)
|
||||||
parent = os.path.join(directory, os.pardir)
|
if parent:
|
||||||
absolute = os.path.abspath(parent)
|
directory = os.path.join(directory, os.pardir)
|
||||||
|
absolute = os.path.abspath(directory)
|
||||||
normalized = os.path.normpath(absolute)
|
normalized = os.path.normpath(absolute)
|
||||||
return normalized
|
return normalized
|
||||||
|
|
||||||
|
@ -58,3 +59,31 @@ def install_requirements(
|
||||||
args.append(path)
|
args.append(path)
|
||||||
|
|
||||||
subprocess.call(args)
|
subprocess.call(args)
|
||||||
|
|
||||||
|
|
||||||
|
def git_clean(remove_directories=False, force=False, dry_run=False, interactive=False, quiet=False, exclude=None,
|
||||||
|
ignore_rules=False, clean_ignored=False, paths=None):
|
||||||
|
command = ['git', 'clean']
|
||||||
|
if remove_directories:
|
||||||
|
command.append('-d')
|
||||||
|
if force:
|
||||||
|
command.append('--force')
|
||||||
|
if interactive:
|
||||||
|
command.append('--interactive')
|
||||||
|
if quiet:
|
||||||
|
command.append('--quiet')
|
||||||
|
if dry_run:
|
||||||
|
command.append('--dry-run')
|
||||||
|
if exclude:
|
||||||
|
command.append('--exclude={pattern}'.format(pattern=exclude))
|
||||||
|
if ignore_rules:
|
||||||
|
command.append('-x')
|
||||||
|
if clean_ignored:
|
||||||
|
command.append('-X')
|
||||||
|
if paths:
|
||||||
|
try:
|
||||||
|
paths = paths.split(' ')
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
command.extend(paths)
|
||||||
|
return subprocess.check_output(command)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue