Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL redirect on plugin installation #387

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions modules/pymol/plugins/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,24 @@ def fetchscript(title, dest=None, run=1, quiet=1):
filename = url = title
rawscript = 1

filename = os.path.join(dest, filename.rsplit('/')[-1])
if not quiet:
print('Downloading', url)

# get page content
try:
from . import pref_get
timeout = pref_get('network_timeout', 10.0)
handle = urllib2.urlopen(url, timeout=timeout)
content = handle.read().decode('utf-8')
filename = handle.url
except IOError as e:
raise CmdException(e, "Plugin-Error")

filename = os.path.join(dest, filename.rsplit('/')[-1])
if os.path.exists(filename):
if not quiet:
print('File "%s" exists, will not redownload')
else:
if not quiet:
print('Downloading', url)

# get page content
try:
content = urlreadstr(url, None if rawscript else 'utf-8')
except IOError as e:
raise CmdException(e, "Plugin-Error")

if not rawscript:
# redirect
redirect = re.match(r'\s*#REDIRECT\s*\[\[(.*?)\]\]', content)
Expand Down Expand Up @@ -356,9 +359,8 @@ def fetchscript(title, dest=None, run=1, quiet=1):
with open(filename, 'w') as handle:
handle.write(content)
else:
with open(filename, 'wb') as handle:
with open(filename, 'w') as handle:
handle.write(content)

if int(run):
cmd.do("run " + filename, echo=not quiet)

Expand Down