Drop support for retired Python 3.5

Upgrade syntax using `pyupgrade --py36-plus` .

Manually drop several `six` imports.

Also:
- Remove broken pr_cache in scripts/bootstrap_history.py
- Fix broken prefix removal in lib/galaxy/tool_util/deps/mulled/mulled_build.py
This commit is contained in:
Nicola Soranzo
2020-10-07 11:52:13 +01:00
parent 57d6a3857d
commit 9d74bba7fb
622 changed files with 1918 additions and 2175 deletions
+8 -7
View File
@@ -1,14 +1,15 @@
"""
Common methods used by the API sample scripts.
"""
from __future__ import print_function
import json
import logging
import sys
from six.moves.urllib.error import HTTPError
from six.moves.urllib.request import Request, urlopen
from urllib.error import HTTPError
from urllib.request import (
Request,
urlopen,
)
log = logging.getLogger(__name__)
@@ -92,7 +93,7 @@ def display(api_key, url, return_formatted=True):
if 'name' in i:
print(' name: %s' % i.pop('name'))
for k, v in i.items():
print(' %s: %s' % (k, v))
print(f' {k}: {v}')
print('')
print('%d element(s) in collection' % len(r))
elif type(r) == dict:
@@ -100,7 +101,7 @@ def display(api_key, url, return_formatted=True):
print('Member Information')
print('------------------')
for k, v in r.items():
print('%s: %s' % (k, v))
print(f'{k}: {v}')
elif type(r) == str:
print(r)
else:
@@ -137,7 +138,7 @@ def submit(api_key, url, data, return_formatted=True):
if 'name' in i:
print(' name: %s' % i.pop('name'))
for k, v in i.items():
print(' %s: %s' % (k, v))
print(f' {k}: {v}')
else:
print(i)
else:
+1 -2
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
@@ -9,7 +8,7 @@ usage = "USAGE: copy_hda_to_library_folder.py <base url> <api key> <hda id> <lib
def copy_hda_to_library_folder(base_url, key, hda_id, library_id, folder_id, message=''):
url = 'http://%s/api/libraries/%s/contents' % (base_url, library_id)
url = f'http://{base_url}/api/libraries/{library_id}/contents'
payload = {
'folder_id' : folder_id,
'create_type' : 'file',
+2 -4
View File
@@ -3,12 +3,10 @@
# Very simple example of using the API to run Data Managers
# Script makes the naive assumption that dbkey==sequence id, which in many cases is not true nor desired
# *** This script is not recommended for use as-is on a production server ***
from __future__ import print_function
import optparse
import time
from six.moves.urllib.parse import urljoin
from urllib.parse import urljoin
from common import get, post # noqa: I100,I202
@@ -35,7 +33,7 @@ def run_tool(tool_id, history_id, params, api_key, galaxy_url, wait=True, sleep_
for i, dataset_dict in enumerate(outputs):
if dataset_is_terminal(dataset_dict['id'], api_key=api_key, galaxy_url=galaxy_url):
finished_datasets.append(i)
for i in reversed(finished_datasets):
for _ in reversed(finished_datasets):
outputs.pop(0)
if wait and outputs:
time.sleep(sleep_time)
+1 -3
View File
@@ -1,10 +1,8 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
from six.moves.urllib.error import URLError
from urllib.error import URLError
from common import display # noqa: I100,I202
+1 -2
View File
@@ -10,7 +10,6 @@ python example_watch_folder.py <api_key> <api_url> /tmp/g_inbox/ /tmp/g_inbox/do
NOTE: The upload method used requires the data library filesystem upload allow_library_path_paste
"""
from __future__ import print_function
import os
import shutil
@@ -65,7 +64,7 @@ def main(api_key, api_url, in_folder, out_folder, data_library, workflow):
# Successful upload of dataset, we have the ldda now. Run the workflow.
wf_data = {}
wf_data['workflow_id'] = workflow['id']
wf_data['history'] = "%s - %s" % (fname, workflow['name'])
wf_data['history'] = "{} - {}".format(fname, workflow['name'])
wf_data['ds_map'] = {}
for step_id, ds_in in workflow['inputs'].items():
wf_data['ds_map'][step_id] = {'src': 'ld', 'id': ds['id']}
+1 -1
View File
@@ -12,7 +12,7 @@ def main():
parser.add_argument('target', metavar='FILE', type=str,
help='file describing data library to fetch')
args = parser.parse_args()
with open(args.target, "r") as f:
with open(args.target) as f:
target = yaml.safe_load(f)
histories_url = args.url + "/api/histories"
@@ -6,7 +6,6 @@ datasets "(not ok)" and the successfully finished datasets "(ok)".
Sample call:
python filter_failed_datasets_from_collection.py <GalaxyUrl> <ApiKey> MySpecialHistory 1234
"""
from __future__ import print_function
import sys
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
@@ -5,7 +5,6 @@ Import one or more exported workflows contained within a specified tool shed rep
Here is a working example of how to use this script to repair a repository installed into Galaxy.
python ./import_workflows_from_installed_tool_shed_repository.py -a 22be3b -l http://localhost:8763/ -n workflow_with_tools -o test -r ef45bb64237e -u http://localhost:9009/
"""
from __future__ import print_function
import argparse
@@ -38,7 +37,7 @@ def main(options):
break
if tool_shed_repository_id:
# Get the list of exported workflows contained in the installed repository.
url = '%s%s' % (base_galaxy_url, '/api/tool_shed_repositories/%s/exported_workflows' % str(tool_shed_repository_id))
url = '{}{}'.format(base_galaxy_url, '/api/tool_shed_repositories/%s/exported_workflows' % str(tool_shed_repository_id))
exported_workflows = display(api_key, url, return_formatted=False)
if exported_workflows:
# Import all of the workflows in the list of exported workflows.
@@ -47,7 +46,7 @@ def main(options):
# data[ 'index' ] = 0
# and change the url to be ~/import_workflow (singular). For example,
# url = '%s%s' % ( base_galaxy_url, '/api/tool_shed_repositories/%s/import_workflow' % str( tool_shed_repository_id ) )
url = '%s%s' % (base_galaxy_url, '/api/tool_shed_repositories/%s/import_workflows' % str(tool_shed_repository_id))
url = '{}{}'.format(base_galaxy_url, '/api/tool_shed_repositories/%s/import_workflows' % str(tool_shed_repository_id))
submit(options.api, url, data)
else:
print("Invalid tool_shed / name / owner / changeset_revision.")
@@ -35,7 +35,7 @@ def main(options):
revision_data['tool_shed_url'] = options.tool_shed_url.rstrip('/')
revision_data['name'] = options.name
revision_data['owner'] = options.owner
revision_url = '%s%s' % (options.local_url.rstrip('/'), '/api/tool_shed_repositories/get_latest_installable_revision')
revision_url = '{}{}'.format(options.local_url.rstrip('/'), '/api/tool_shed_repositories/get_latest_installable_revision')
latest_installable_revision = submit(options.api,
revision_url,
revision_data,
@@ -49,7 +49,7 @@ def main(options):
data['install_repository_dependencies'] = options.install_repository_dependencies
if options.install_tool_dependencies:
data['install_tool_dependencies'] = options.install_tool_dependencies
submit(options.api, '%s%s' % (options.local_url.rstrip('/'), '/api/tool_shed_repositories/new/install_repository_revision'), data)
submit(options.api, '{}{}'.format(options.local_url.rstrip('/'), '/api/tool_shed_repositories/new/install_repository_revision'), data)
if __name__ == '__main__':
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
+2 -3
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
@@ -8,7 +7,7 @@ import sys
from bioblend import galaxy
class Uploader(object):
class Uploader:
def __init__(self, url, api, library_id, folder_id, should_link,
non_local):
@@ -132,7 +131,7 @@ class Uploader(object):
# So that we can check if it really needs to be uploaded.
already_uploaded = memo_key in self.memo_path.keys()
fid = self.memoized_path(basepath, base_folder=self.folder_id)
print('[%s/%s] %s/%s uploaded=%s' % (idx + 1, len(all_files), fid, fname, already_uploaded))
print('[{}/{}] {}/{} uploaded={}'.format(idx + 1, len(all_files), fid, fname, already_uploaded))
if not already_uploaded:
if self.non_local:
@@ -3,7 +3,6 @@
Example usage:
./library_upload_from_import_dir.py <key> http://127.0.0.1:8080/api/libraries/dda47097d9189f15/contents Fdda47097d9189f15 auto /Users/EnisAfgan/projects/pprojects/galaxy/lib_upload_dir ?
"""
from __future__ import print_function
import os
import sys
-1
View File
@@ -9,7 +9,6 @@ python load_data_with_metadata.py <api_key> <api_url> /data/folder "API Imports"
NOTE: The upload method used requires the data library filesystem upload allow_library_path_paste
"""
from __future__ import print_function
import argparse
import json
+2 -3
View File
@@ -5,7 +5,6 @@ Repair a specified repository revision previously installed into Galaxy.
Here is a working example of how to use this script to repair a repository installed into Galaxy.
./repair_tool_shed_repository.py --api <api key> --local <galaxy base url> --url http://testtoolshed.g2.bx.psu.edu --name gregs_filter --owner greg --revision f28d5018f9cb
"""
from __future__ import print_function
import argparse
@@ -26,7 +25,7 @@ def main(options):
base_galaxy_url = options.local_url.rstrip('/')
base_tool_shed_url = options.tool_shed_url.rstrip('/')
cleaned_tool_shed_url = clean_url(base_tool_shed_url)
installed_tool_shed_repositories_url = '%s/api/%s' % (base_galaxy_url, 'tool_shed_repositories')
installed_tool_shed_repositories_url = '{}/api/{}'.format(base_galaxy_url, 'tool_shed_repositories')
data = {}
data['tool_shed_url'] = cleaned_tool_shed_url
data['name'] = options.name
@@ -43,7 +42,7 @@ def main(options):
tool_shed_repository_id = installed_tool_shed_repository['id']
break
if tool_shed_repository_id:
url = '%s%s' % (base_galaxy_url, '/api/tool_shed_repositories/%s/repair_repository_revision' % str(tool_shed_repository_id))
url = '{}{}'.format(base_galaxy_url, '/api/tool_shed_repositories/%s/repair_repository_revision' % str(tool_shed_repository_id))
submit(options.api, url, data)
else:
print("Invalid tool_shed / name / owner / changeset_revision.")
+1 -2
View File
@@ -1,7 +1,6 @@
"""
Sample script for Galaxy Search API
"""
from __future__ import print_function
import json
import sys
@@ -9,7 +8,7 @@ import sys
import requests
class RemoteGalaxy(object):
class RemoteGalaxy:
def __init__(self, url, api_key):
self.url = url
-1
View File
@@ -2,7 +2,6 @@
"""
Upload a file to the desired history.
"""
from __future__ import print_function
import json
import os
-1
View File
@@ -8,7 +8,6 @@ API example script for deleting workflows
Example calls:
python workflow_delete.py <api_key> <galaxy_url>/api/workflows/<workflow id> True
"""
from __future__ import print_function
import os
import sys
-1
View File
@@ -5,7 +5,6 @@ Example calls:
python workflow_execute.py <api_key> <galaxy_url>/api/workflows f2db41e1fa331b3e 'Test API History' '38=ldda=0qr350234d2d192f'
python workflow_execute.py <api_key> <galaxy_url>/api/workflows f2db41e1fa331b3e 'hist_id=a912e9e5d84530d4' '38=hda=03501d7626bd192f'
"""
from __future__ import print_function
import os
import sys
@@ -9,7 +9,6 @@ Example calls:
python workflow_execute.py <api_key> <galaxy_url>/api/workflows <workflow_id> 'hist_id=<history_id>' '38=hda=<file_id>' 'param=tool=name=value'
python workflow_execute_parameters.py <api_key> http://localhost:8080/api/workflows 1cd8e2f6b131e891 'Test API' '69=ld=a799d38679e985db' '70=ld=33b43b4e7093c91f' 'param=peakcalling_spp=aligner=bowtie' 'param=bowtie_wrapper=suppressHeader=True' 'param=peakcalling_spp=window_size=1000'
"""
from __future__ import print_function
import os
import sys
-1
View File
@@ -4,7 +4,6 @@ Import workflows from the command line.
Example calls:
python workflow_import.py <api_key> <galaxy_url> '/path/to/workflow/file [--add_to_menu]'
"""
from __future__ import print_function
import os
import sys
@@ -3,7 +3,6 @@
python rpark_import_workflow_from_file.py 35a24ae2643785ff3d046c98ea362c7f http://localhost:8080/api/workflows/import 'spp_submodule.ga'
python rpark_import_workflow_from_file.py 35a24ae2643785ff3d046c98ea362c7f http://localhost:8080/api/workflows/import 'spp_submodule.ga'
"""
from __future__ import print_function
import json
import os
+1 -1
View File
@@ -6,7 +6,7 @@ import time
from bioblend.galaxy import GalaxyInstance
class ApplyTagsHistory(object):
class ApplyTagsHistory:
@classmethod
def __init__(self, galaxy_url, galaxy_api_key, history_id=None):
+3 -3
View File
@@ -16,7 +16,7 @@ except ImportError:
def handle_timeout(signum, stack):
raise IOError("Timed out reading input")
raise OSError("Timed out reading input")
# set timeout so we don't block on reading stdin
@@ -32,10 +32,10 @@ signal.alarm(0)
p_auth = pam.pam()
authenticated = p_auth.authenticate(pam_username, pam_password, service=pam_service)
if authenticated:
log.debug('PAM auth helper: authentication successful for {}'.format(pam_username))
log.debug(f'PAM auth helper: authentication successful for {pam_username}')
sys.stdout.write('True\n')
sys.exit(0)
else:
log.debug('PAM auth helper: authentication failed for {}'.format(pam_username))
log.debug(f'PAM auth helper: authentication failed for {pam_username}')
sys.stdout.write('False\n')
sys.exit(1)
+20 -27
View File
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# Little script to make HISTORY.rst more easy to format properly, lots TODO
# pull message down and embed, use arg parse, handle multiple, etc...
from __future__ import print_function
import calendar
import datetime
@@ -13,6 +12,7 @@ import string
import sys
import textwrap
from collections import OrderedDict
from urllib.parse import urljoin
try:
import requests
@@ -22,8 +22,6 @@ try:
from github import Github
except ImportError:
Github = None
from six import string_types
from six.moves.urllib.parse import urljoin
log = logging.getLogger(__name__)
@@ -31,8 +29,8 @@ PROJECT_DIRECTORY = os.path.join(os.path.dirname(__file__), os.pardir)
GALAXY_VERSION_FILE = os.path.join(PROJECT_DIRECTORY, "lib", "galaxy", "version.py")
PROJECT_OWNER = "galaxyproject"
PROJECT_NAME = "galaxy"
PROJECT_URL = "https://github.com/%s/%s" % (PROJECT_OWNER, PROJECT_NAME)
PROJECT_API = "https://api.github.com/repos/%s/%s/" % (PROJECT_OWNER, PROJECT_NAME)
PROJECT_URL = f"https://github.com/{PROJECT_OWNER}/{PROJECT_NAME}"
PROJECT_API = f"https://api.github.com/repos/{PROJECT_OWNER}/{PROJECT_NAME}/"
RELEASES_PATH = os.path.join(PROJECT_DIRECTORY, "doc", "source", "releases")
RELEASE_DELTA_MONTHS = 4 # Number of months between releases.
@@ -332,7 +330,7 @@ def release_issue(argv):
)
release_issue_contents = RELEASE_ISSUE_TEMPLATE.safe_substitute(**release_issue_template_params)
github = _github_client()
repo = github.get_repo("%s/%s" % (PROJECT_OWNER, PROJECT_NAME))
repo = github.get_repo(f"{PROJECT_OWNER}/{PROJECT_NAME}")
repo.create_issue(
title="Publication of Galaxy Release v %s" % release_name,
body=release_issue_contents,
@@ -430,15 +428,15 @@ def check_blocking_issues(argv):
def _pr_to_str(pr):
if isinstance(pr, string_types):
if isinstance(pr, str):
return pr
return "PR #%s (%s) %s" % (pr.number, pr.title, pr.html_url)
return f"PR #{pr.number} ({pr.title}) {pr.html_url}"
def _issue_to_str(pr):
if isinstance(pr, string_types):
if isinstance(pr, str):
return pr
return "Issue #%s (%s) %s" % (pr.number, pr.title, pr.html_url)
return f"Issue #{pr.number} ({pr.title}) {pr.html_url}"
def _next_version_params(release_name):
@@ -469,13 +467,10 @@ def _release_dates(version):
return freeze_date, release_date
def _get_prs(release_name, state="closed", pr_cache=[]):
def _get_prs(release_name, state="closed"):
github = _github_client()
repo = github.get_repo("%s/%s" % (PROJECT_OWNER, PROJECT_NAME))
add_to_cache = not pr_cache
pull_requests = pr_cache or repo.get_pulls(
state=state,
)
repo = github.get_repo(f"{PROJECT_OWNER}/{PROJECT_NAME}")
pull_requests = repo.get_pulls(state=state)
reached_old_prs = False
for pr in pull_requests:
@@ -490,8 +485,6 @@ def _get_prs(release_name, state="closed", pr_cache=[]):
proper_state = state != "closed" or merged_at
if not proper_state or not milestone or milestone.title != release_name:
continue
if add_to_cache:
pr_cache.append(pr)
yield pr
@@ -545,7 +538,7 @@ def main(argv):
def extend_target(target, line, source=history):
from_str = ".. %s\n" % target
if target not in source:
raise Exception("Failed to find target [%s] in source [%s]" % (target, source))
raise Exception(f"Failed to find target [{target}] in source [{source}]")
return source.replace(from_str, from_str + line + "\n")
ident = argv[1]
@@ -590,10 +583,10 @@ def main(argv):
text = ".. _Pull Request {0}: {1}/pull/{0}".format(pull_request, PROJECT_URL)
prs_content = extend_target("github_links", text, prs_content)
if owner:
to_doc += "\n(thanks to `@%s <https://github.com/%s>`__)." % (
to_doc += "\n(thanks to `@{} <https://github.com/{}>`__).".format(
owner, owner,
)
to_doc += "\n`Pull Request {0}`_".format(pull_request)
to_doc += f"\n`Pull Request {pull_request}`_"
labels = None
if req and 'labels' in req:
labels = req['labels']
@@ -602,12 +595,12 @@ def main(argv):
issue = ident[len("issue"):]
text = ".. _Issue {0}: {1}/issues/{0}".format(issue, PROJECT_URL)
prs_content = extend_target("github_links", text, prs_content)
to_doc += "`Issue {0}`_".format(issue)
to_doc += f"`Issue {issue}`_"
else:
short_rev = ident[:7]
text = ".. _{0}: {1}/commit/{0}".format(short_rev, PROJECT_URL)
prs_content = extend_target("github_links", text, prs_content)
to_doc += "{0}_".format(short_rev)
to_doc += f"{short_rev}_"
to_doc = wrap(to_doc)
if text_target is not None:
@@ -626,7 +619,7 @@ def main(argv):
def _read_file(path):
with open(path, "r") as f:
with open(path) as f:
return f.read()
@@ -637,7 +630,7 @@ def _write_file(path, contents):
def _text_target(pull_request, labels=None):
pr_number = None
if isinstance(pull_request, string_types):
if isinstance(pull_request, str):
pr_number = pull_request
else:
pr_number = pull_request.number
@@ -738,7 +731,7 @@ def _releases():
def _github_client():
try:
github_json_path = os.path.expanduser("~/.github.json")
with open(github_json_path, "r") as fh:
with open(github_json_path) as fh:
github_json_dict = json.load(fh)
github = Github(**github_json_dict)
except Exception:
@@ -764,7 +757,7 @@ def process_sentence(message):
# Strip tags like [15.07].
message = re.sub(r"^\s*\[.*\]\s*", r"", message)
# Link issues and pull requests...
issue_url = "https://github.com/%s/%s/issues" % (PROJECT_OWNER, PROJECT_NAME)
issue_url = f"https://github.com/{PROJECT_OWNER}/{PROJECT_NAME}/issues"
message = re.sub(r'#(\d+)', r'`#\1 <%s/\1>`__' % issue_url, message)
return message
+1 -3
View File
@@ -1,5 +1,3 @@
from __future__ import print_function
import os
from xml.etree import ElementTree as ET
@@ -36,7 +34,7 @@ def getfilenamelist(startdir):
return filenamelist
class ToolBox(object):
class ToolBox:
def __init__(self):
from collections import defaultdict
self.tools = defaultdict(list)
+2 -3
View File
@@ -2,20 +2,19 @@
If the current installed Python version is not supported, prints an error
message to stderr and returns 1
"""
from __future__ import print_function
import sys
def check_python():
if sys.version_info[:2] >= (3, 5):
if sys.version_info[:2] >= (3, 6):
# supported
return
else:
version_string = '.'.join(str(_) for _ in sys.version_info[:3])
msg = """\
ERROR: Your Python version is: %s
Galaxy is currently supported on Python >=3.5 .
Galaxy is currently supported on Python >=3.6 .
To run Galaxy, please install a supported Python version.
If a supported version is already installed but is not your default,
https://docs.galaxyproject.org/en/latest/admin/python.html contains instructions
@@ -36,7 +36,6 @@ Email Template Variables:
Author: Lance Parsons (lparsons@princeton.edu)
"""
from __future__ import print_function
import argparse
import logging
@@ -134,7 +133,7 @@ def main():
if os.path.exists(default_template):
template_file = default_template
elif os.path.exists(sample_template_file):
print("Copying %s to %s" % (sample_template_file, default_template))
print(f"Copying {sample_template_file} to {default_template}")
shutil.copyfile(sample_template_file, default_template)
template_file = default_template
else:
+1 -2
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import argparse
import logging
@@ -515,7 +514,7 @@ def _purge_folder(folder, app, remove_from_disk, info_only=False):
app.sa_session.flush()
class CleanupDatasetsApplication(object):
class CleanupDatasetsApplication:
"""Encapsulates the state of a Universe application"""
def __init__(self, config):
self.object_store = build_object_store_from_config(config)
+8 -9
View File
@@ -4,7 +4,6 @@ pgcleanup.py - A script for cleaning up datasets in Galaxy efficiently, by
bypassing the Galaxy model and operating directly on the database.
PostgreSQL 9.1 or greater is required.
"""
from __future__ import print_function
import argparse
import datetime
@@ -54,7 +53,7 @@ class LevelFormatter(logging.Formatter):
return logging.Formatter.format(self, record)
class Action(object):
class Action:
"""Base class for all actions.
When writing new actions, the following things happen automatically:
@@ -204,11 +203,11 @@ class Action(object):
def _log_results(self, results, primary_key):
for primary in sorted(results.keys()):
self.log.info('%s: %s' % (primary_key, primary))
self.log.info(f'{primary_key}: {primary}')
for causal, s in zip(self.causals, results[primary]):
for r in sorted(s):
secondaries = ', '.join('%s: %s' % x for x in zip(causal[1:], r[1:]))
self.log.info('%s %s caused %s' % (causal[0], r[0], secondaries))
self.log.info('{} {} caused {}'.format(causal[0], r[0], secondaries))
def handle_results(self, cur):
results = {}
@@ -233,7 +232,7 @@ class Action(object):
pass
class RemovesObjects(object):
class RemovesObjects:
"""Base class for mixins that remove objects from object stores.
"""
def _init(self):
@@ -280,7 +279,7 @@ class RemovesObjects(object):
#
class PurgesHDAs(object):
class PurgesHDAs:
"""Avoid repetition in queries that purge HDAs, since they must also delete MetadataFiles and ICDAs.
To use, place ``{purge_hda_dependencies_sql}`` somewhere in your CTEs after a ``purged_hda_ids`` CTE returning HDA
@@ -336,7 +335,7 @@ class PurgesHDAs(object):
)
class RequiresDiskUsageRecalculation(object):
class RequiresDiskUsageRecalculation:
"""Causes disk usage to be recalculated for affected users.
To use, ensure your query returns a ``recalculate_disk_usage_user_id`` column.
@@ -626,7 +625,7 @@ class PurgeDeletedUsers(PurgesHDAs, RemovesMetadataFiles, Action):
)
def _init(self):
super(PurgeDeletedUsers, self)._init()
super()._init()
self.__zero_disk_usage_user_ids = set()
self._register_row_method(self.collect_zero_disk_usage_user_id)
self._register_post_method(self.zero_disk_usage)
@@ -952,7 +951,7 @@ class PurgeDatasets(RemovesDatasets, Action):
"""
class Cleanup(object):
class Cleanup:
def __init__(self):
self.args = None
self.config = None
@@ -6,7 +6,6 @@ Populates blank uuid fields in datasets with randomly generated values
Going forward, these ids will be generated for all new datasets. This
script fixes datasets that were generated before the change.
"""
from __future__ import print_function
import argparse
import os
@@ -30,7 +30,6 @@ from datetime import timedelta
from functools import update_wrapper
import flask.ext.login as flask_login
import six
from flask import (
current_app,
Flask,
@@ -109,9 +108,9 @@ def crossdomain(origin=None, methods=None, headers=None,
automatic_options=True):
if methods is not None:
methods = ', '.join(sorted(x.upper() for x in methods))
if headers is not None and not isinstance(headers, six.string_types):
if headers is not None and not isinstance(headers, str):
headers = ', '.join(x.upper() for x in headers)
if not isinstance(origin, six.string_types):
if not isinstance(origin, str):
origin = ', '.join(origin)
if isinstance(max_age, timedelta):
max_age = max_age.total_seconds()
@@ -168,14 +167,14 @@ def static_style():
@socketio.on('event connect', namespace='/chat')
def event_connect(message):
log.info("%s connected" % (current_user.username,))
log.info(f"{current_user.username} connected")
@socketio.on('event broadcast', namespace='/chat')
def event_broadcast(message):
message = sanitize_html(message['data'])
log.debug("%s broadcast '%s'" % (current_user.username, message))
log.debug(f"{current_user.username} broadcast '{message}'")
emit('event response',
{'data': message, 'user': current_user.username, 'gravatar': hashlib.md5(current_user.email).hexdigest()}, broadcast=True)
@@ -186,7 +185,7 @@ def send_room_message(message):
data = sanitize_html(message['data'])
room = sanitize_html(message['room'])
log.debug("%s sent '%s' to %s" % (current_user.username, message, room))
log.debug(f"{current_user.username} sent '{message}' to {room}")
emit('event response room',
{'data': data, 'user': current_user.username, 'gravatar': hashlib.md5(current_user.email).hexdigest(), 'chatroom': room}, room=room)
@@ -202,7 +201,7 @@ def event_disconnect(message):
def join(message):
room = sanitize_html(message['room'])
log.debug("%s joined %s" % (current_user.username, room))
log.debug(f"{current_user.username} joined {room}")
join_room(room)
emit('event response room',
@@ -213,7 +212,7 @@ def join(message):
def leave(message):
room = sanitize_html(message['room'])
log.debug("%s left %s" % (current_user.username, room))
log.debug(f"{current_user.username} left {room}")
leave_room(room)
emit('event response room',
+1 -3
View File
@@ -1,5 +1,3 @@
from __future__ import print_function
import sys
@@ -13,7 +11,7 @@ def main():
except KeyError:
sample = "config/galaxy.ini.sample"
for line in open(sample, "r"):
for line in open(sample):
is_app_main = line.startswith('[app:main]')
if not found_app_main and not is_app_main:
continue
+3 -9
View File
@@ -13,15 +13,12 @@
# You can also use this script as a library, for instance see https://gist.github.com/1979583
# TODO: This script overlaps a lot with manage_db.py and create_db.py,
# these should maybe be refactored to remove duplication.
from __future__ import print_function
import datetime
import decimal
import os.path
import sys
from six import string_types
# Setup DB scripting environment
from sqlalchemy import * # noqa
from sqlalchemy.orm import * # noqa
@@ -36,9 +33,6 @@ from galaxy.model import set_datatypes_registry # More explicit than `*` import
from galaxy.model.mapping import init
from galaxy.model.orm.scripts import get_config
if sys.version_info > (3,):
long = int
registry = Registry()
registry.load_datatypes()
set_datatypes_registry(registry)
@@ -71,7 +65,7 @@ def printquery(statement, bind=None):
self, bindparam, within_columns_clause=False,
literal_binds=False, **kwargs
):
return super(LiteralCompiler, self).render_literal_bindparam(
return super().render_literal_bindparam(
bindparam,
within_columns_clause=within_columns_clause,
literal_binds=literal_binds,
@@ -88,12 +82,12 @@ def printquery(statement, bind=None):
of the DBAPI.
"""
if isinstance(value, string_types):
if isinstance(value, str):
value = value.replace("'", "''")
return "'%s'" % value
elif value is None:
return "NULL"
elif isinstance(value, (float, int, long)):
elif isinstance(value, (float, int)):
return repr(value)
elif isinstance(value, decimal.Decimal):
return str(value)
+6 -7
View File
@@ -2,7 +2,6 @@
"""
Docker Swarm mode management
"""
from __future__ import absolute_import, print_function
import argparse
import errno
@@ -58,7 +57,7 @@ SWARM_MANAGER_CONF_DEFAULTS = {
log = logging.getLogger(__name__)
class SwarmManager(object):
class SwarmManager:
def __init__(self, conf, docker_interface):
self._conf = conf
@@ -93,7 +92,7 @@ class SwarmManager(object):
p = subprocess.Popen(raw_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True)
stdout, stderr = p.communicate()
if p.returncode not in allowed_returncodes:
msg = "error running '%s': returned %s" % (raw_cmd, p.returncode)
msg = f"error running '{raw_cmd}': returned {p.returncode}"
if attempt < command_retries + 1:
msg += ', waiting %s seconds' % self._conf.command_retry_wait
time.sleep(self._conf.command_retry_wait)
@@ -172,10 +171,10 @@ class SwarmManager(object):
node_task_ids = [t.id for nt in [n.tasks for n in nodes] for t in nt]
envs = {}
for service in services:
envs[service.id] = ['%s=%s' % (k, service.env.get(k, 'unset')) for k in self._conf.log_environment_variables]
envs[service.id] = ['{}={}'.format(k, service.env.get(k, 'unset')) for k in self._conf.log_environment_variables]
log.info('%s nodes, %s services (%s terminal)', len(nodes), len(services), len(terminal))
if terminal:
service_strs = ['%s (state: %s)' % (s.name, s.state) for s in terminal]
service_strs = [f'{s.name} (state: {s.state})' for s in terminal]
log.info('terminal services: %s', ', '.join(service_strs) or 'none')
for service in services:
unassigned_tasks = [t for t in service.tasks if t.id not in node_task_ids]
@@ -291,7 +290,7 @@ class SwarmManager(object):
return ready
class SwarmState(object):
class SwarmState:
def __init__(self, conf, interface_conf):
self._conf = conf
@@ -558,7 +557,7 @@ def _load_xdg_environment():
def _swarm_manager_pidfile(conf):
try:
os.makedirs(os.path.dirname(conf['pid_file']))
except (IOError, OSError) as exc:
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
return daemon.pidfile.PIDLockFile(conf['pid_file'])
+1 -2
View File
@@ -5,7 +5,6 @@ Submit a DRMAA job given a user id and a job template file (in JSON format)
defining any or all of the following: args, remoteCommand, outputPath,
errorPath, nativeSpecification, name, email, project
"""
from __future__ import print_function
import errno
import json
@@ -118,7 +117,7 @@ def main():
# then the pbs cluster_files_directory does not need to
# be readable by all users
json_file_exists(json_filename)
with open(json_filename, 'r') as f:
with open(json_filename) as f:
data = json.load(f)
set_user(userid, assign_all_groups)
# Added to disable LSF generated messages that would interfer with this
+1 -3
View File
@@ -11,8 +11,6 @@ run from the Galaxy root.
% python script/edam_mapping.py > edam_mapping.tsv
"""
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
@@ -59,4 +57,4 @@ for ext, edam_format in sorted(datatypes_registry.edam_formats.items()):
edam_info = format_info[edam_format]
edam_label = edam_info["label"]
edam_definition = edam_info["definition"]
print("%s\t%s\t%s\t%s" % (ext, edam_format, edam_label, edam_definition))
print(f"{ext}\t{edam_format}\t{edam_label}\t{edam_definition}")
+1 -1
View File
@@ -30,7 +30,7 @@ def __main__():
if not os.path.isfile(file_path):
# Nothing to do - some splitters don't write a JSON file
sys.exit(0)
data = json.load(open(file_path, 'r'))
data = json.load(open(file_path))
try:
class_name_parts = data['class_name'].split('.')
module_name = '.'.join(class_name_parts[:-1])
+2 -2
View File
@@ -65,7 +65,7 @@ def main():
hastoolboxpos = True
if (not (hastags and hastoolboxpos)):
original = open(toolconffile, 'r')
original = open(toolconffile)
contents = original.readlines()
original.close()
@@ -124,7 +124,7 @@ def getfnl(startdir):
try:
doc = ET.parse(fullfn)
except Exception as e:
raise Exception("Oops, bad XML in '%s': %s" % (fullfn, e))
raise Exception(f"Oops, bad XML in '{fullfn}': {e}")
rootelement = doc.getroot()
# here we check if this xml file actually is a tool conf xml!
if rootelement.tag == 'tool':
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
from os import pardir
from os.path import (
+1 -2
View File
@@ -29,10 +29,9 @@ import signal
import sys
import threading
from argparse import ArgumentParser
from configparser import ConfigParser
from logging.config import fileConfig
from six.moves.configparser import ConfigParser
try:
from daemonize import Daemonize
except ImportError:
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
+9 -13
View File
@@ -1,11 +1,7 @@
from __future__ import print_function
import os
import shlex
import sys
from six import string_types
from six.moves import shlex_quote
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'lib')))
from galaxy.util.path import get_ext
@@ -49,13 +45,13 @@ def __add_arg(args, arg, value):
if isinstance(value, bool):
if value is True:
args.append(optarg)
elif isinstance(value, string_types):
elif isinstance(value, str):
# the = in --optarg=value is usually, but not always, optional
if value.startswith('='):
args.append(shlex_quote(optarg + value))
args.append(shlex.quote(optarg + value))
else:
args.append(optarg)
args.append(shlex_quote(value))
args.append(shlex.quote(value))
else:
[__add_arg(args, arg, v) for v in value]
@@ -91,8 +87,8 @@ def _get_uwsgi_args(cliargs, kwargs):
'threads': '4',
'buffer-size': '16384', # https://github.com/galaxyproject/galaxy/issues/1530
'http': 'localhost:{port}'.format(port=DEFAULT_PORTS[cliargs.app]),
'static-map': ('/static={here}/static'.format(here=os.getcwd()),
'/favicon.ico={here}/static/favicon.ico'.format(here=os.getcwd())),
'static-map': (f'/static={os.getcwd()}/static',
f'/favicon.ico={os.getcwd()}/static/favicon.ico'),
'die-on-term': True,
'enable-threads': True,
'hook-master-start': ('unix_signal:2 gracefully_kill_them_all',
@@ -106,7 +102,7 @@ def _get_uwsgi_args(cliargs, kwargs):
if cliargs.app in ["tool_shed"]:
__add_arg(args, 'module', 'tool_shed.webapp.buildapp:uwsgi_app()')
else:
__add_arg(args, 'module', 'galaxy.webapps.{app}.buildapp:uwsgi_app()'.format(app=cliargs.app))
__add_arg(args, 'module', f'galaxy.webapps.{cliargs.app}.buildapp:uwsgi_app()')
# only include virtualenv if it's set/exists, otherwise this breaks conda-env'd Galaxy
if not __arg_set('virtualenv', uwsgi_kwargs) and ('VIRTUAL_ENV' in os.environ or os.path.exists('.venv')):
__add_arg(args, 'virtualenv', os.environ.get('VIRTUAL_ENV', '.venv'))
@@ -118,9 +114,9 @@ def _get_uwsgi_args(cliargs, kwargs):
# route: ^/static/scripts/bundled/ http:127.0.0.1:8081
if hmr_server.lower() in ['1', 'true', 'default']:
hmr_server = "http:127.0.0.1:8081"
__add_arg(args, 'route', '^/static/dist/ {hmr_server}'.format(hmr_server=hmr_server))
__add_arg(args, 'route', f'^/static/dist/ {hmr_server}')
# We always want to append client/src/assets as static-safe.
__add_arg(args, 'static-safe', '{here}/client/src/assets'.format(here=os.getcwd()))
__add_arg(args, 'static-safe', f'{os.getcwd()}/client/src/assets')
for arg in DEFAULT_ARGS['_all_'] + DEFAULT_ARGS[cliargs.app]:
if not __arg_set(arg, uwsgi_kwargs):
+9 -10
View File
@@ -4,7 +4,6 @@
See doc/source/admin/grt.rst for more detailed usage information.
"""
import argparse
import io
import json
import logging
import os
@@ -47,7 +46,7 @@ def _init(args):
def kw_metrics(job):
return {
'%s_%s' % (metric.plugin, metric.metric_name): metric.metric_value
f'{metric.plugin}_{metric.metric_name}': metric.metric_value
for metric in job.metrics
}
@@ -100,7 +99,7 @@ def main(argv):
REPORT_BASE = os.path.join(REPORT_DIR, REPORT_IDENTIFIER)
if os.path.exists(CHECK_POINT_FILE):
with open(CHECK_POINT_FILE, 'r') as handle:
with open(CHECK_POINT_FILE) as handle:
last_job_sent = int(handle.read())
else:
last_job_sent = -1
@@ -133,7 +132,7 @@ def main(argv):
if end_job_id - last_job_sent > args.max_records:
end_job_id = last_job_sent + args.max_records
annotate('endpoint_end', 'Processing jobs (%s, %s]' % (last_job_sent, end_job_id))
annotate('endpoint_end', f'Processing jobs ({last_job_sent}, {end_job_id}]')
# Remember the last job sent.
if end_job_id == last_job_sent:
@@ -146,8 +145,8 @@ def main(argv):
blacklisted_tools = config['sanitization']['tools']
annotate('export_jobs_start', 'Exporting Jobs')
with io.open(REPORT_BASE + '.jobs.tsv', 'w', encoding='utf-8') as handle_job:
handle_job.write(u'\t'.join(('id', 'tool_id', 'tool_version', 'state', 'create_time')) + '\n')
with open(REPORT_BASE + '.jobs.tsv', 'w', encoding='utf-8') as handle_job:
handle_job.write('\t'.join(('id', 'tool_id', 'tool_version', 'state', 'create_time')) + '\n')
for offset_start in range(last_job_sent, end_job_id, args.batch_size):
logging.debug("Processing %s:%s", offset_start, min(end_job_id, offset_start + args.batch_size))
for job in sa_session.query(model.Job.id, model.Job.user_id, model.Job.tool_id, model.Job.tool_version, model.Job.state, model.Job.create_time) \
@@ -178,8 +177,8 @@ def main(argv):
annotate('export_jobs_end')
annotate('export_datasets_start', 'Exporting Datasets')
with io.open(REPORT_BASE + '.datasets.tsv', 'w', encoding='utf-8') as handle_datasets:
handle_datasets.write(u'\t'.join(('job_id', 'dataset_id', 'extension', 'file_size', 'param_name', 'type')) + '\n')
with open(REPORT_BASE + '.datasets.tsv', 'w', encoding='utf-8') as handle_datasets:
handle_datasets.write('\t'.join(('job_id', 'dataset_id', 'extension', 'file_size', 'param_name', 'type')) + '\n')
for offset_start in range(last_job_sent, end_job_id, args.batch_size):
logging.debug("Processing %s:%s", offset_start, min(end_job_id, offset_start + args.batch_size))
@@ -258,8 +257,8 @@ def main(argv):
annotate('export_datasets_end')
annotate('export_metric_num_start', 'Exporting Metrics (Numeric)')
with io.open(REPORT_BASE + '.metric_num.tsv', 'w', encoding='utf-8') as handle_metric_num:
handle_metric_num.write(u'\t'.join(('job_id', 'plugin', 'name', 'value')) + '\n')
with open(REPORT_BASE + '.metric_num.tsv', 'w', encoding='utf-8') as handle_metric_num:
handle_metric_num.write('\t'.join(('job_id', 'plugin', 'name', 'value')) + '\n')
for offset_start in range(last_job_sent, end_job_id, args.batch_size):
logging.debug("Processing %s:%s", offset_start, min(end_job_id, offset_start + args.batch_size))
for metric in sa_session.query(model.JobMetricNumeric.job_id, model.JobMetricNumeric.plugin, model.JobMetricNumeric.metric_name, model.JobMetricNumeric.metric_value) \
+1 -1
View File
@@ -43,7 +43,7 @@ def main(argv):
# Contact the server and check auth details.
headers = {
'AUTHORIZATION': '%s:%s' % (GRT_INSTANCE_ID, GRT_API_KEY)
'AUTHORIZATION': f'{GRT_INSTANCE_ID}:{GRT_API_KEY}'
}
r = requests.post(GRT_URL + 'api/whoami', headers=headers)
data = r.json()
+4 -5
View File
@@ -4,7 +4,6 @@ A command line helper for common operations performed by Galaxy maintainers.
Encodes and decodes IDs, returns Dataset IDs if provided an HDA or LDDA id,
returns the disk path of a dataset.
"""
from __future__ import print_function
import argparse
import os
@@ -30,10 +29,10 @@ helper = idencoding.IdEncodingHelper(id_secret=app_properties.get('id_secret'))
model = galaxy.config.init_models_from_config(config)
if args.encode_id:
print('Encoded "%s": %s' % (args.encode_id, helper.encode_id(args.encode_id)))
print('Encoded "{}": {}'.format(args.encode_id, helper.encode_id(args.encode_id)))
if args.decode_id:
print('Decoded "%s": %s' % (args.decode_id, helper.decode_id(args.decode_id)))
print('Decoded "{}": {}'.format(args.decode_id, helper.decode_id(args.decode_id)))
if args.hda_id:
try:
@@ -41,7 +40,7 @@ if args.hda_id:
except Exception:
hda_id = int(helper.decode_id(args.hda_id))
hda = model.context.current.query(model.HistoryDatasetAssociation).get(hda_id)
print('HDA "%s" is Dataset "%s" at: %s' % (hda.id, hda.dataset.id, hda.file_name))
print(f'HDA "{hda.id}" is Dataset "{hda.dataset.id}" at: {hda.file_name}')
if args.ldda_id:
try:
@@ -49,4 +48,4 @@ if args.ldda_id:
except Exception:
ldda_id = int(helper.decode_id(args.ldda_id))
ldda = model.context.current.query(model.HistoryDatasetAssociation).get(ldda_id)
print('LDDA "%s" is Dataset "%s" at: %s' % (ldda.id, ldda.dataset.id, ldda.file_name))
print(f'LDDA "{ldda.id}" is Dataset "{ldda.dataset.id}" at: {ldda.file_name}')
+7 -8
View File
@@ -23,7 +23,6 @@ usage: %prog [options]
-a, --append=a: Append to existing all_fasta.loc file rather than create new
-p, --sample-text=p: Copy over text from all_fasta.loc.sample file (false if set to append)
"""
from __future__ import print_function
import optparse
import os
@@ -197,7 +196,7 @@ def __main__():
if len(options.fasta_exts) == 1:
print('with the extension %s.' % ', '.join(fasta_exts[:-1]))
else:
print('with the extension %s or %s.' % (', '.join(fasta_exts[:-1]), fasta_exts[-1]))
print('with the extension {} or {}.'.format(', '.join(fasta_exts[:-1]), fasta_exts[-1]))
print('\nSkipping the following:\n\t%s' % '\n\t'.join(exemptions))
# get column names
@@ -217,7 +216,7 @@ def __main__():
if cols:
col_values = [col.strip() for col in cols.split(',')]
if not col_values or not loc_path:
raise Exception('No columns can be found for this data table (%s) in %s' % (options.data_table, options.data_table_xml))
raise Exception(f'No columns can be found for this data table ({options.data_table}) in {options.data_table_xml}')
# get all fasta paths under genome directory
fasta_locs = {}
@@ -225,7 +224,7 @@ def __main__():
genome_subdirs = [dr for dr in os.listdir(options.genome_dir) if dr not in exemptions]
for genome_subdir in genome_subdirs:
possible_names = [genome_subdir]
possible_names.extend(['%s%s' % (genome_subdir, _) for _ in variants])
possible_names.extend([f'{genome_subdir}{_}' for _ in variants])
# get paths to all fasta files
for path_to_look_in in paths_to_look_in:
for dirpath, dirnames, filenames in os.walk(path_to_look_in % genome_subdir):
@@ -238,17 +237,17 @@ def __main__():
name = DBKEY_DESCRIPTION_MAP[genome_subdir]
else:
try:
name = '%s %s' % (DBKEY_DESCRIPTION_MAP[genome_subdir], VARIANT_MAP[fasta_base.replace(genome_subdir, '')])
name = '{} {}'.format(DBKEY_DESCRIPTION_MAP[genome_subdir], VARIANT_MAP[fasta_base.replace(genome_subdir, '')])
except KeyError:
name = '%s %s' % (DBKEY_DESCRIPTION_MAP[genome_subdir], fasta_base.replace(genome_subdir, ''))
name = '{} {}'.format(DBKEY_DESCRIPTION_MAP[genome_subdir], fasta_base.replace(genome_subdir, ''))
fasta_locs[fasta_base] = {'value': fasta_base, 'dbkey': genome_subdir, 'name': name, 'path': os.path.join(dirpath, fn)}
else:
unmatching_fasta_paths.append(os.path.join(dirpath, fn))
# remove redundant fasta files
for k, v in variant_exclusions.items():
leave_in = '%s%s' % (genome_subdir, k)
leave_in = f'{genome_subdir}{k}'
if leave_in in fasta_locs:
to_remove = ['%s%s' % (genome_subdir, _) for _ in v]
to_remove = [f'{genome_subdir}{_}' for _ in v]
for tr in to_remove:
if tr in fasta_locs:
del fasta_locs[tr]
-1
View File
@@ -3,7 +3,6 @@
convert nt and wgs data (fasta format) to giNumber_seqLen
run formatdb in the command line: gunzip -c nt.gz |formatdb -i stdin -p F -n "nt.chunk" -v 2000
"""
from __future__ import print_function
import sys
+9 -10
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# Dan Blankenberg
from __future__ import print_function
import os
import sys
@@ -21,7 +20,7 @@ def __main__():
for file in files:
if file[-5:] == ".info":
tmp_dict = {}
info_file = open(os.path.join(this_base_dir, file), 'r')
info_file = open(os.path.join(this_base_dir, file))
info = info_file.readlines()
info_file.close()
for line in info:
@@ -48,26 +47,26 @@ def __main__():
continue
if 'build' in org:
build = org['build']
print("ORG\t%s\t%s\t%s\t%s\t%s\t%s\tUCSC" % (build, org['name'], org['kingdom'], org['group'], org['chromosomes'], org['info url']))
print("ORG\t{}\t{}\t{}\t{}\t{}\t{}\tUCSC".format(build, org['name'], org['kingdom'], org['group'], org['chromosomes'], org['info url']))
else:
print("ORG\t%s\t%s\t%s\t%s\t%s\t%s\tNone" % (build, org['name'], org['kingdom'], org['group'], org['chromosomes'], org['info url']))
print("ORG\t{}\t{}\t{}\t{}\t{}\t{}\tNone".format(build, org['name'], org['kingdom'], org['group'], org['chromosomes'], org['info url']))
for chr in org['chrs']:
chr = org['chrs'][chr]
print("CHR\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (build, chr['chromosome'], chr['name'], chr['length'], chr['gi'], chr['gb'], "http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=nucleotide&val=" + chr['refseq']))
print("CHR\t{}\t{}\t{}\t{}\t{}\t{}\t{}".format(build, chr['chromosome'], chr['name'], chr['length'], chr['gi'], chr['gb'], "http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=nucleotide&val=" + chr['refseq']))
for feature in ['CDS', 'tRNA', 'rRNA']:
print("DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % (build, chr['chromosome'], feature, build, chr['chromosome'], feature, "bed", os.path.join(org['base_dir'], "%s.%s.bed" % (chr['chromosome'], feature))))
print("DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(build, chr['chromosome'], feature, build, chr['chromosome'], feature, "bed", os.path.join(org['base_dir'], "{}.{}.bed".format(chr['chromosome'], feature))))
# FASTA
print("DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % (build, chr['chromosome'], "seq", build, chr['chromosome'], "sequence", "fasta", os.path.join(org['base_dir'], "%s.fna" % chr['chromosome'])))
print("DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(build, chr['chromosome'], "seq", build, chr['chromosome'], "sequence", "fasta", os.path.join(org['base_dir'], "%s.fna" % chr['chromosome'])))
# GeneMark
if os.path.exists(os.path.join(org['base_dir'], "%s.GeneMark.bed" % chr['chromosome'])):
print("DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % (build, chr['chromosome'], "GeneMark", build, chr['chromosome'], "GeneMark", "bed", os.path.join(org['base_dir'], "%s.GeneMark.bed" % chr['chromosome'])))
print("DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(build, chr['chromosome'], "GeneMark", build, chr['chromosome'], "GeneMark", "bed", os.path.join(org['base_dir'], "%s.GeneMark.bed" % chr['chromosome'])))
# GenMarkHMM
if os.path.exists(os.path.join(org['base_dir'], "%s.GeneMarkHMM.bed" % chr['chromosome'])):
print("DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % (build, chr['chromosome'], "GeneMarkHMM", build, chr['chromosome'], "GeneMarkHMM", "bed", os.path.join(org['base_dir'], "%s.GeneMarkHMM.bed" % chr['chromosome'])))
print("DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(build, chr['chromosome'], "GeneMarkHMM", build, chr['chromosome'], "GeneMarkHMM", "bed", os.path.join(org['base_dir'], "%s.GeneMarkHMM.bed" % chr['chromosome'])))
# Glimmer3
if os.path.exists(os.path.join(org['base_dir'], "%s.Glimmer3.bed" % chr['chromosome'])):
print("DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % (build, chr['chromosome'], "Glimmer3", build, chr['chromosome'], "Glimmer3", "bed", os.path.join(org['base_dir'], "%s.Glimmer3.bed" % chr['chromosome'])))
print("DATA\t{}_{}_{}\t{}\t{}\t{}\t{}\t{}".format(build, chr['chromosome'], "Glimmer3", build, chr['chromosome'], "Glimmer3", "bed", os.path.join(org['base_dir'], "%s.Glimmer3.bed" % chr['chromosome'])))
if __name__ == "__main__":
+1 -2
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# Dan Blankenberg
from __future__ import print_function
import os
import sys
@@ -21,7 +20,7 @@ def __main__():
for file in files:
if file[-5:] == ".info":
tmp_dict = {}
info_file = open(os.path.join(this_base_dir, file), 'r')
info_file = open(os.path.join(this_base_dir, file))
info = info_file.readlines()
info_file.close()
for line in info:
+3 -4
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# Dan Blankenberg
from __future__ import print_function
import os
import sys
@@ -30,7 +29,7 @@ def __main__():
for file in files:
if file[-5:] == ".info":
tmp_dict = {}
info_file = open(os.path.join(this_base_dir, file), 'r')
info_file = open(os.path.join(this_base_dir, file))
info = info_file.readlines()
info_file.close()
for line in info:
@@ -68,7 +67,7 @@ def __main__():
print("Skipping", build)
# continue
loc_out.write("seq %s %s\n" % (build, seq_path))
loc_out.write(f"seq {build} {seq_path}\n")
# Print org info
@@ -79,7 +78,7 @@ def __main__():
nib_out_file = os.path.join(seq_path, "%s.nib " % chr['chromosome'])
# create nibs using faToNib binary
# TODO: when bx supports writing nib, use it here instead
command = "faToNib %s %s" % (fasta_file, nib_out_file)
command = f"faToNib {fasta_file} {nib_out_file}"
os.system(command)
loc_out.close()
+3 -4
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# Dan Blankenberg
from __future__ import print_function
import os
import sys
@@ -21,7 +20,7 @@ def __main__():
for file in files:
if file[-5:] == ".info":
tmp_dict = {}
info_file = open(os.path.join(this_base_dir, file), 'r')
info_file = open(os.path.join(this_base_dir, file))
info = info_file.readlines()
info_file.close()
for line in info:
@@ -53,8 +52,8 @@ def __main__():
chrs = []
for chrom in org['chrs']:
chrom = org['chrs'][chrom]
chrs.append("%s=%s" % (chrom['chromosome'], chrom['length']))
print("%s\t%s\t%s" % (build, org['name'], ",".join(chrs)))
chrs.append("{}={}".format(chrom['chromosome'], chrom['length']))
print("{}\t{}\t{}".format(build, org['name'], ",".join(chrs)))
if __name__ == "__main__":
+9 -10
View File
@@ -4,19 +4,18 @@
# Harvest Bacteria
# Connects to NCBI's Microbial Genome Projects website and scrapes it for information.
# Downloads and converts annotations for each Genome
from __future__ import print_function
import os
import sys
import time
from ftplib import FTP
from urllib.request import urlretrieve
import requests
try:
from bs4 import BeautifulSoup
except ImportError:
raise Exception("BeautifulSoup4 library not found, please install it, e.g. with 'pip install BeautifulSoup4'")
from six.moves.urllib.request import urlretrieve
from util import ( # noqa: I202
get_bed_from_genbank,
@@ -52,7 +51,7 @@ def iter_genome_projects(url="http://www.ncbi.nlm.nih.gov/genomes/lproks.cgi?vie
group = fields[3].split(">")[-1]
info_url = "%s%s" % (info_url_base, org_num)
info_url = f"{info_url_base}{org_num}"
org_genbank = fields[7].split("\">")[-1].split("<")[0].split(".")[0]
org_refseq = fields[8].split("\">")[-1].split("<")[0].split(".")[0]
@@ -74,7 +73,7 @@ def get_chroms_by_project_id(org_num, base_url="http://www.ncbi.nlm.nih.gov/entr
html = None
while html_count < 500 and html is None:
html_count += 1
url = "%s%s" % (base_url, org_num)
url = f"{base_url}{org_num}"
try:
html = requests.get(url).text
except Exception:
@@ -116,11 +115,11 @@ def get_ftp_contents(ftp_url):
def scrape_ftp(ftp_contents, org_dir, org_num, refseq, ftp_url):
for file_type, items in desired_ftp_files.items():
ext = items['ext']
ftp_filename = "%s.%s" % (refseq, ext)
target_filename = os.path.join(org_dir, "%s.%s" % (refseq, ext))
ftp_filename = f"{refseq}.{ext}"
target_filename = os.path.join(org_dir, f"{refseq}.{ext}")
if ftp_filename in ftp_contents:
url_count = 0
url = "%s/%s" % (ftp_url, ftp_filename)
url = f"{ftp_url}/{ftp_filename}"
results = None
while url_count < 500 and results is None:
url_count += 1
@@ -152,7 +151,7 @@ def process_FASTA(filename, org_num, refseq):
# Create Chrom Info File:
chrom_info_file = open(os.path.join(os.path.split(filename)[0], "%s.info" % refseq), 'wb+')
chrom_info_file.write("chromosome=%s\nname=%s\nlength=%s\norganism=%s\n" % (refseq, chr_name, len(fasta), org_num))
chrom_info_file.write("chromosome={}\nname={}\nlength={}\norganism={}\n".format(refseq, chr_name, len(fasta), org_num))
try:
chrom_info_file.write("gi=%s\n" % accesions['gi'])
except Exception:
@@ -172,7 +171,7 @@ def process_Genbank(filename, org_num, refseq):
# extracts 'CDS', 'tRNA', 'rRNA' features from genbank file
features = get_bed_from_genbank(filename, refseq, ['CDS', 'tRNA', 'rRNA'])
for feature, values in features.items():
feature_file = open(os.path.join(os.path.split(filename)[0], "%s.%s.bed" % (refseq, feature)), 'wb+')
feature_file = open(os.path.join(os.path.split(filename)[0], f"{refseq}.{feature}.bed"), 'wb+')
feature_file.write('\n'.join(values))
feature_file.close()
print("Genbank extraction finished for chrom:", refseq, "file:", filename)
@@ -225,7 +224,7 @@ def __main__():
except Exception:
print("path '%s' seems to already exist" % base_dir)
for org_num, name, chroms, kingdom, group, org_genbank, org_refseq, info_url, ftp_url in iter_genome_projects():
for org_num, name, chroms, kingdom, group, _, _, info_url, ftp_url in iter_genome_projects():
if chroms is None:
continue # No chrom information, we can't really do anything with this organism
# Create org directory, if exists, assume it is done and complete --> skip it
+2 -4
View File
@@ -3,15 +3,13 @@
Walk downloaded Genome Projects and Convert, in place, IDs to match the UCSC Archaea browser, where applicable.
Uses UCSC Archaea DSN.
"""
from __future__ import print_function
import os
import sys
from shutil import move
from urllib.request import urlopen
from xml.etree import ElementTree
from six.moves.urllib.request import urlopen
def __main__():
base_dir = os.path.join(os.getcwd(), "bacteria")
@@ -26,7 +24,7 @@ def __main__():
for file in files:
if file[-5:] == ".info":
tmp_dict = {}
info_file = open(os.path.join(this_base_dir, file), 'r')
info_file = open(os.path.join(this_base_dir, file))
info = info_file.readlines()
info_file.close()
for line in info:
+5 -5
View File
@@ -7,7 +7,7 @@ assert sys.version_info[:2] >= (2, 4)
# genbank_to_bed
class Region(object):
class Region:
def __init__(self):
self.qualifiers = {}
self.start = None
@@ -37,7 +37,7 @@ class Region(object):
self.end = end
class GenBankFeatureParser(object):
class GenBankFeatureParser:
"""Parses Features from Single Locus GenBank file"""
def __init__(self, fh, features_list=[]):
self.fh = fh
@@ -90,9 +90,9 @@ class GenBankFeatureParser(object):
else:
# continuation of multi-line qualifier content
if last_feature_name.lower() in ['translation']:
self.features[last_feature_name][-1].qualifiers[last_attr_name][-1] = "%s%s" % (self.features[last_feature_name][-1].qualifiers[last_attr_name][-1], line.rstrip('"'))
self.features[last_feature_name][-1].qualifiers[last_attr_name][-1] = "{}{}".format(self.features[last_feature_name][-1].qualifiers[last_attr_name][-1], line.rstrip('"'))
else:
self.features[last_feature_name][-1].qualifiers[last_attr_name][-1] = "%s %s" % (self.features[last_feature_name][-1].qualifiers[last_attr_name][-1], line.rstrip('"'))
self.features[last_feature_name][-1].qualifiers[last_attr_name][-1] = "{} {}".format(self.features[last_feature_name][-1].qualifiers[last_attr_name][-1], line.rstrip('"'))
def get_features_by_type(self, feature_type):
if feature_type not in self.features:
@@ -117,7 +117,7 @@ def get_bed_from_genbank(gb_file, chrom, feature_list):
if not name:
name = "unknown"
features[feature_type].append("%s\t%s\t%s\t%s\t%s\t%s" % (chrom, feature.start, feature.end, name, 0, feature.strand)) # append new bed field here
features[feature_type].append("{}\t{}\t{}\t{}\t{}\t{}".format(chrom, feature.start, feature.end, name, 0, feature.strand)) # append new bed field here
return features
+13 -13
View File
@@ -75,7 +75,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
db_connection_info = None
if start_dataset_id > end_dataset_id:
print("Error: start_dataset_id {} cannot be larger than end_dataset_id {}".format(start_dataset_id, end_dataset_id))
print(f"Error: start_dataset_id {start_dataset_id} cannot be larger than end_dataset_id {end_dataset_id}")
return
# read object_store_info file
@@ -135,7 +135,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
object_store_path = object_store_info.get(object_store_id)
if object_store_path is None:
print("Error: object_store_info_file does not have a value for {}".format(object_store_id))
print(f"Error: object_store_info_file does not have a value for {object_store_id}")
raise Exception
irods_resc = get_irods_resource(conn, objectid, object_store_id, irods_info)
@@ -155,7 +155,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
# Add disk file to collection
options = {kw.REG_CHKSUM_KW : '', kw.RESC_NAME_KW: irods_resc}
session.data_objects.put(disk_file_path, irods_file_path, **options)
print("Copied disk file {} to irods {}".format(disk_file_path, irods_file_path))
print(f"Copied disk file {disk_file_path} to irods {irods_file_path}")
if os.path.isdir(disk_folder_path):
disk_folder_path_all_files = disk_folder_path + "/*"
@@ -165,7 +165,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
iput_command = "iput -R " + irods_resc + " -rk " + disk_folder_path_all_files + " " + irods_folder_collection_path
subprocess.call(iput_command, shell=True)
print("Copied disk folder {} to irods {}".format(disk_folder_path, irods_folder_collection_path))
print(f"Copied disk folder {disk_folder_path} to irods {irods_folder_collection_path}")
if copy_or_checksum == "checksum":
# Calculate disk file checksum. Then get the file checksum from irods and compare it with the calculated disk file checksum
@@ -177,7 +177,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
# obj.checksum is prepended with 'sha2:'. Remove that so we can compare it to disk file checksum
irods_file_checksum = obj.checksum[5:]
if irods_file_checksum != disk_file_checksum:
print("Error: irods file checksum {} does not match disk file checksum {} for irods file {} and disk file {}".format(irods_file_checksum, disk_file_checksum, irods_file_path, disk_file_path))
print(f"Error: irods file checksum {irods_file_checksum} does not match disk file checksum {disk_file_checksum} for irods file {irods_file_path} and disk file {disk_file_path}")
continue
except (DataObjectDoesNotExist, CollectionDoesNotExist) as e:
print(e)
@@ -207,7 +207,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
# obj.checksum is prepended with 'sha2:'. Remove that so we can compare it to disk file checksum
an_irods_file_checksum = obj.checksum[5:]
if an_irods_file_checksum != a_disk_file_checksum:
print("Error: irods file checksum {} does not match disk file checksum {} for irods file {} and disk file {}".format(an_irods_file_checksum, a_disk_file_checksum, an_irods_file_path, a_disk_file_path))
print(f"Error: irods file checksum {an_irods_file_checksum} does not match disk file checksum {a_disk_file_checksum} for irods file {an_irods_file_path} and disk file {a_disk_file_path}")
continue
except (DataObjectDoesNotExist, CollectionDoesNotExist) as e:
print(e)
@@ -217,7 +217,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
continue
# Delete file on disk
print("Removing directory {}".format(disk_folder_path))
print(f"Removing directory {disk_folder_path}")
shutil.rmtree(disk_folder_path)
# Update object store id
@@ -231,7 +231,7 @@ def copy_files_to_irods(start_dataset_id, end_dataset_id, object_store_info_file
update_cursor.close()
# Delete file on disk
print("Removing file {}".format(disk_file_path))
print(f"Removing file {disk_file_path}")
os.remove(disk_file_path)
except Exception as e:
@@ -261,12 +261,12 @@ def get_irods_resource(conn, objectid, object_store_id, irods_info):
read_cursor.execute(last_accessed_sql_statement, args)
row = read_cursor.fetchone()
if row is None:
print("Could not find the last access time for dataset with id {}. Returning the default resc {}.".format(objectid, irods_resc))
print(f"Could not find the last access time for dataset with id {objectid}. Returning the default resc {irods_resc}.")
return irods_resc
dataset_id = row[0]
if int(dataset_id) != objectid:
print("The returned dataset id {} does not match the passed in datsetid {}. Returning the default resc {}.".format(dataset_id, objectid, irods_resc))
print(f"The returned dataset id {dataset_id} does not match the passed in datsetid {objectid}. Returning the default resc {irods_resc}.")
return irods_resc
max_create_time = row[1]
@@ -274,10 +274,10 @@ def get_irods_resource(conn, objectid, object_store_id, irods_info):
max_create_time_dt = max_create_time.replace(tzinfo=None)
# If the last time a dataset was accessed was prior to a cuttoff date, use the tape resource. Otherwise, use the regular (non-tape) resource
if max_create_time_dt < irods_tape_resc_cuttoff_dt:
print("The last time dataset with id {} was accessed {} is prior to tape resource cuttoff {}. Using tape resource in irods.".format(objectid, max_create_time_dt, irods_tape_resc_cuttoff_dt))
print(f"The last time dataset with id {objectid} was accessed {max_create_time_dt} is prior to tape resource cuttoff {irods_tape_resc_cuttoff_dt}. Using tape resource in irods.")
return irods_tape_resc
print("The last time dataset with id {} was accessed {} is after the tape resource cuttoff {}. Using regular (non-tape) resource in irods.".format(objectid, max_create_time_dt, irods_tape_resc_cuttoff_dt))
print(f"The last time dataset with id {objectid} was accessed {max_create_time_dt} is after the tape resource cuttoff {irods_tape_resc_cuttoff_dt}. Using regular (non-tape) resource in irods.")
return irods_resc
except Exception as e:
@@ -287,7 +287,7 @@ def get_irods_resource(conn, objectid, object_store_id, irods_info):
def get_file_checksum(disk_file_path):
checksum_cmd = "shasum -a 256 {} | xxd -r -p | base64".format(disk_file_path)
checksum_cmd = f"shasum -a 256 {disk_file_path} | xxd -r -p | base64"
disk_file_checksum = subprocess.check_output(checksum_cmd, shell=True)
# remove '\n' from the end of disk_file_checksum
disk_file_checksum_len = len(disk_file_checksum)
-1
View File
@@ -4,7 +4,6 @@ Bootstrap the Galaxy framework.
This should not be called directly! Use the run.sh script in Galaxy's
top level directly.
"""
from __future__ import absolute_import
import os
import sys
+1 -3
View File
@@ -1,5 +1,3 @@
from __future__ import print_function
import glob
import os
import shutil
@@ -25,7 +23,7 @@ def stage_static(f):
else:
shutil.copy(src, dest)
except Exception:
print("Error copying '%s' to '%s'" % (src, dest))
print(f"Error copying '{src}' to '{dest}'")
raise
+2 -3
View File
@@ -29,7 +29,6 @@ Examples
# 2 days:
% ./runtime_stats.py -c galaxy.ini --like -m $((2 * 60)) -M $((2 * 24 * 60 * 60)) 'tophat2'
"""
from __future__ import print_function
import argparse
import os
@@ -136,7 +135,7 @@ def query(tool_id=None, user=None, like=None, source='metrics',
connect_arg_str = ''
for k, v in connect_args.items():
connect_arg_str += '%s=%s' % (k, v)
connect_arg_str += f'{k}={v}'
pc = psycopg2.connect(connect_arg_str)
cur = pc.cursor()
@@ -149,7 +148,7 @@ def query(tool_id=None, user=None, like=None, source='metrics',
field = 'username'
else:
field = 'email'
sql = 'SELECT id FROM galaxy_user WHERE %s = %s' % (field, '%s')
sql = 'SELECT id FROM galaxy_user WHERE {} = {}'.format(field, '%s')
cur.execute(sql, (user,))
if debug:
print('Executed:')
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
+2 -4
View File
@@ -1,5 +1,3 @@
from __future__ import print_function
import os
import string
import sys
@@ -7,7 +5,7 @@ import sys
SCRIPTS_DIRECTORY = os.path.dirname(__file__)
TEMPLATE_PATH = os.path.join(SCRIPTS_DIRECTORY, "slideshow_template.html")
TEMPLATE = string.Template(open(TEMPLATE_PATH, "r").read())
TEMPLATE = string.Template(open(TEMPLATE_PATH).read())
def main(argv=None):
@@ -16,7 +14,7 @@ def main(argv=None):
title = argv[1]
markdown_source = argv[2]
output = os.path.splitext(markdown_source)[0] + '.html'
with open(markdown_source, "r") as s:
with open(markdown_source) as s:
content = s.read()
html = TEMPLATE.safe_substitute(**{
'title': title,
+1 -2
View File
@@ -1,5 +1,4 @@
"""Script to parse timings out of a Galaxy log and summarize."""
from __future__ import print_function
import re
from argparse import ArgumentParser
@@ -24,7 +23,7 @@ def main(argv=None):
pattern_str = args.pattern
filter_pattern = re.compile(pattern_str) if pattern_str is not None else None
times = []
for line in open(args.file, "r"):
for line in open(args.file):
if filter_pattern and not filter_pattern.search(line):
continue
+7 -11
View File
@@ -1,12 +1,8 @@
from __future__ import print_function
import json
import os
import sys
import six
from six.moves.urllib.error import HTTPError
from six.moves.urllib.request import (
from urllib.error import HTTPError
from urllib.request import (
build_opener,
HTTPRedirectHandler,
install_opener,
@@ -94,7 +90,7 @@ def display(url, api_key=None, return_formatted=True):
# Only return the first 1K of errors.
print(e.read(1024))
sys.exit(1)
if isinstance(r, six.text_type):
if isinstance(r, str):
print('error: %s' % r)
return None
if not return_formatted:
@@ -111,7 +107,7 @@ def display(url, api_key=None, return_formatted=True):
if 'name' in i:
print(' name: %s' % i.pop('name'))
for k, v in i.items():
print(' %s: %s' % (k, v))
print(f' {k}: {v}')
print()
print('%d element(s) in collection' % len(r))
elif isinstance(r, dict):
@@ -119,7 +115,7 @@ def display(url, api_key=None, return_formatted=True):
print('Member Information')
print('------------------')
for k, v in r.items():
print('%s: %s' % (k, v))
print(f'{k}: {v}')
else:
print('response is unknown type: %s' % type(r))
@@ -133,7 +129,7 @@ def get(url, api_key=None):
sys.exit("URL did not return JSON data")
def get_api_url(base, parts=[], params=None):
def get_api_url(base, parts, params=None):
"""Compose and return a URL for the Tool Shed API."""
if 'api' in parts and parts.index('api') != 0:
parts.pop(parts.index('api'))
@@ -271,7 +267,7 @@ def submit(url, data, api_key=None, return_formatted=True):
if 'name' in i:
print(' name: %s' % i.pop('name'))
for k, v in i.items():
print(' %s: %s' % (k, v))
print(f' {k}: {v}')
else:
print(i)
else:
@@ -17,7 +17,6 @@ available in the test public Tool Shed and create each of them in a local develo
./create_categories.py -a <api key> -f http://testtoolshed.g2.bx.psu.edu -t http://localhost:9009
"""
from __future__ import print_function
import argparse
-1
View File
@@ -18,7 +18,6 @@ are available in the test public Tool Shed and create each of them in a local de
./create_users.py -a <api key> -f http://testtoolshed.g2.bx.psu.edu -t http://localhost:9009
"""
from __future__ import print_function
import argparse
@@ -1,11 +1,10 @@
#!/usr/bin/env python
from __future__ import print_function
import optparse
import os
import sys
from configparser import ConfigParser
from six.moves.configparser import ConfigParser
from sqlalchemy.exc import OperationalError, ProgrammingError
sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'lib'))
@@ -99,7 +98,7 @@ def get_local_tool_shed_url(config_parser):
if config_parser.has_option('server:main', 'port'):
port = config_parser.get('server:main', 'port')
host = '127.0.0.1'
print('http://%s:%s' % (host, port))
print(f'http://{host}:{port}')
return 0
@@ -115,7 +114,7 @@ def main(args):
return check_db(config_parser)
elif args.method == 'admin_user_info':
(username, email, password) = admin_user_info()
print('%s__SEP__%s__SEP__%s' % (username, email, password))
print(f'{username}__SEP__{email}__SEP__{password}')
return 0
elif args.method == 'get_url':
return get_local_tool_shed_url(config_parser)
@@ -1,12 +1,10 @@
#!/usr/bin/env python
from __future__ import print_function
import logging
import optparse
import os
import sys
from six.moves.configparser import ConfigParser
from configparser import ConfigParser
sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'lib'))
sys.path.insert(1, os.path.join(os.path.dirname(__file__)))
@@ -24,7 +22,7 @@ from bootstrap_util import admin_user_info # noqa: I100,I201
log = logging.getLogger(__name__)
class BootstrapApplication(object):
class BootstrapApplication:
"""
Creates a basic Tool Shed application in order to discover the database connection and use SQL
to create a user and API key.
@@ -10,7 +10,6 @@ Make sure you adjust your Toolshed config to:
This script expects the Tool Shed's runtime virtualenv to be active.
"""
from __future__ import print_function
import argparse
import logging
@@ -1,6 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
import configparser
import logging
import os
import string
@@ -12,7 +12,6 @@ from optparse import OptionParser
from time import strftime
import sqlalchemy as sa
from six.moves import configparser
from sqlalchemy import and_, distinct, false, not_
sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'lib'))
@@ -92,7 +91,7 @@ def send_mail_to_owner(app, owner, email, repositories_deprecated, days=14):
body += '\n'.join(build_citable_url(url, repository) for repository in repositories_deprecated)
try:
galaxy_send_mail(from_address, email, subject, body, app.config)
print("# An email has been sent to %s, the owner of %s." % (owner, ', '.join(repository.name for repository in repositories_deprecated)))
print("# An email has been sent to {}, the owner of {}.".format(owner, ', '.join(repository.name for repository in repositories_deprecated)))
return True
except Exception as e:
print("# An error occurred attempting to send email: %s" % e)
@@ -130,10 +129,10 @@ def deprecate_repositories(app, cutoff_time, days=14, info_only=False, verbose=F
.filter(app.model.Repository.table.c.id == repository_id).one()
owner = repository.user
if info_only:
print('# Repository %s owned by %s would have been deprecated, but info_only was set.' % (repository.name, repository.user.username))
print(f'# Repository {repository.name} owned by {repository.user.username} would have been deprecated, but info_only was set.')
else:
if verbose:
print('# Deprecating repository %s owned by %s.' % (repository.name, owner.username))
print(f'# Deprecating repository {repository.name} owned by {owner.username}.')
if owner.username not in repositories_by_owner:
repositories_by_owner[owner.username] = dict(owner=owner, repositories=[])
repositories_by_owner[owner.username]['repositories'].append(repository)
@@ -152,7 +151,7 @@ def deprecate_repositories(app, cutoff_time, days=14, info_only=False, verbose=F
print("####################################################################################")
class DeprecateRepositoriesApplication(object):
class DeprecateRepositoriesApplication:
"""Encapsulates the state of a Universe application"""
def __init__(self, config):
if config.database_connection is False:
-1
View File
@@ -1,7 +1,6 @@
# Dan Blankenberg
# This script checks maf_index.loc file for inconsistencies between what is listed as available and what is really available.
# Make sure that required dependencies (e.g. galaxy_root/lib) are included in your PYTHONPATH
from __future__ import print_function
import sys
+1 -1
View File
@@ -21,7 +21,7 @@ def __main__():
suffix = 're_match_multiline'
else:
suffix = 're_match'
output = open("%s.%s" % (args[0], suffix), 'wb')
output = open("{}.{}".format(args[0], suffix), 'wb')
if options.multiline:
lines = [re.escape(input.read())]
else:
+2 -4
View File
@@ -1,10 +1,8 @@
from __future__ import print_function
import argparse
import os
import sys
from configparser import ConfigParser
from six.moves.configparser import SafeConfigParser
from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
@@ -27,7 +25,7 @@ def main(opts, session, model):
def create_database(config_file):
parser = SafeConfigParser()
parser = ConfigParser()
parser.read(config_file)
# Determine which database connection to use.
database_connection = parser.get('app:main', 'install_database_connection')