Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#61: python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hugbug committed Aug 6, 2020
1 parent d5486cc commit 2226670
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
15 changes: 10 additions & 5 deletions VideoSort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# VideoSort post-processing script for NZBGet.
#
# Copyright (C) 2013-2018 Andrey Prygunkov <[email protected]>
# Copyright (C) 2013-2020 Andrey Prygunkov <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -36,9 +36,9 @@
# Author: Andrey Prygunkov ([email protected]).
# Web-site: http://nzbget.net/VideoSort.
# License: GPLv3 (http://www.gnu.org/licenses/gpl.html).
# PP-Script Version: 8.0.
# PP-Script Version: 9.0.
#
# NOTE: This script requires Python 2.x to be installed on your system.
# NOTE: This script requires Python 2.x or 3.x to be installed on your system.

##############################################################################
### OPTIONS ###
Expand Down Expand Up @@ -271,6 +271,11 @@
import guessit
import difflib

try:
unicode
except NameError:
unicode = str

# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_NONE=95
Expand Down Expand Up @@ -811,7 +816,7 @@ def add_series_mapping(guess, mapping):
episode_num_just = episodes[0].rjust(2, '0') + episode_separator + episodes[-1].rjust(2, '0')
else: # if multiple_episodes == 'list':
for episode_num in episodes:
ep_prefix = episode_separator if episode_num_all <> '' else ''
ep_prefix = episode_separator if episode_num_all != '' else ''
episode_num_all += ep_prefix + episode_num
episode_num_just += ep_prefix + episode_num.rjust(2,'0')

Expand Down Expand Up @@ -1162,7 +1167,7 @@ def construct_path(filename):
old_path = ''
while old_path != path:
old_path = path
for key, name in REPLACE_AFTER.iteritems():
for key, name in REPLACE_AFTER.items():
path = path.replace(key, name)

path = path.replace('%up', '..')
Expand Down
36 changes: 21 additions & 15 deletions lib/pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
"""

import sys, os, zipimport, time, re, imp, types
from urlparse import urlparse, urlunparse
#PY3: from urlparse import urlparse, urlunparse

#PY3:
try:
basestring
except NameError:
basestring = str

try:
frozenset
Expand Down Expand Up @@ -48,7 +54,7 @@
# attribute is present to decide wether to reinstall the package
_distribute = True

def _bypass_ensure_directory(name, mode=0777):
def _bypass_ensure_directory(name, mode=0o777):
# Sandbox-bypassing version of ensure_directory()
if not WRITE_SUPPORT:
raise IOError('"os.mkdir" not supported on this platform.')
Expand All @@ -62,20 +68,20 @@ def _bypass_ensure_directory(name, mode=0777):

def _declare_state(vartype, **kw):
g = globals()
for name, val in kw.iteritems():
for name, val in kw.items():
g[name] = val
_state_vars[name] = vartype

def __getstate__():
state = {}
g = globals()
for k, v in _state_vars.iteritems():
for k, v in _state_vars.items():
state[k] = g['_sget_'+v](g[k])
return state

def __setstate__(state):
g = globals()
for k, v in state.iteritems():
for k, v in state.items():
g['_sset_'+_state_vars[k]](k, g[k], v)
return state

Expand Down Expand Up @@ -660,7 +666,7 @@ def find_plugins(self,
try:
resolvees = shadow_set.resolve(req, env, installer)

except ResolutionError,v:
except ResolutionError as v:
error_info[dist] = v # save error info
if fallback:
continue # try the next older version of project
Expand Down Expand Up @@ -718,11 +724,11 @@ def __getstate__(self):
return (self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
self.callbacks[:])

def __setstate__(self, (entries, keys, by_key, callbacks)):
self.entries = entries[:]
self.entry_keys = keys.copy()
self.by_key = by_key.copy()
self.callbacks = callbacks[:]
def __setstate__(self, o):
self.entries = o.entries[:]
self.entry_keys = o.keys.copy()
self.by_key = o.by_key.copy()
self.callbacks = o.callbacks[:]



Expand Down Expand Up @@ -1031,7 +1037,7 @@ def postprocess(self, tempname, filename):

if os.name == 'posix':
# Make the resource executable
mode = ((os.stat(tempname).st_mode) | 0555) & 07777
mode = ((os.stat(tempname).st_mode) | 0o555) & 0o7777
os.chmod(tempname, mode)


Expand Down Expand Up @@ -1249,7 +1255,7 @@ def run_script(self,script_name,namespace):
len(script_text), 0, script_text.split('\n'), script_filename
)
script_code = compile(script_text,script_filename,'exec')
exec script_code in namespace, namespace
#PY3: exec script_code in namespace, namespace

def _has(self, path):
raise NotImplementedError(
Expand Down Expand Up @@ -2302,7 +2308,7 @@ def __str__(self):
def __getattr__(self,attr):
"""Delegate all unrecognized public attributes to .metadata provider"""
if attr.startswith('_'):
raise AttributeError,attr
raise AttributeError #PY3: raise AttributeError,attr
return getattr(self._provider, attr)

#@classmethod
Expand Down Expand Up @@ -2670,7 +2676,7 @@ def __eq__(self,other):

def __contains__(self,item):
if isinstance(item,Distribution):
if item.key <> self.key: return False
if item.key != self.key: return False
if self.index: item = item.parsed_version # only get if we need it
elif isinstance(item,basestring):
item = parse_version(item)
Expand Down

0 comments on commit 2226670

Please sign in to comment.