mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-28 02:58:18 +08:00
Replace removed mercurial repo.opener() method
with a simple `get_hgrc_path()` function. Also some refactoring.
This commit is contained in:
@@ -4,7 +4,6 @@ import re
|
||||
import shutil
|
||||
|
||||
from markupsafe import escape
|
||||
from six.moves import configparser
|
||||
from six.moves.urllib.error import HTTPError
|
||||
from sqlalchemy import and_, false, or_
|
||||
|
||||
@@ -18,16 +17,6 @@ log = logging.getLogger(__name__)
|
||||
VALID_REPOSITORYNAME_RE = re.compile(r"^[a-z0-9\_]+$")
|
||||
|
||||
|
||||
def change_repository_name_in_hgrc_file(hgrc_file, new_name):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(hgrc_file)
|
||||
config.read(hgrc_file)
|
||||
config.set('web', 'name', new_name)
|
||||
new_file = open(hgrc_file, 'wb')
|
||||
config.write(new_file)
|
||||
new_file.close()
|
||||
|
||||
|
||||
def check_for_updates(app, model, repository_id=None):
|
||||
message = ''
|
||||
status = 'ok'
|
||||
@@ -617,7 +606,6 @@ def set_repository_attributes(app, repository, status, error_message, deleted, u
|
||||
|
||||
|
||||
__all__ = (
|
||||
'change_repository_name_in_hgrc_file',
|
||||
'check_for_updates',
|
||||
'check_or_update_tool_shed_status_for_installed_repository',
|
||||
'create_or_update_tool_shed_repository',
|
||||
|
||||
@@ -61,6 +61,10 @@ def commit_changeset(repo_path, full_path_to_changeset, username, message):
|
||||
raise Exception(error_message)
|
||||
|
||||
|
||||
def get_hgrc_path(repo_path):
|
||||
return os.path.join(repo_path, '.hg', 'hgrc')
|
||||
|
||||
|
||||
def create_hgrc_file(app, repository):
|
||||
# Since we support both http and https, we set `push_ssl` to False to
|
||||
# override the default (which is True) in the Mercurial API.
|
||||
@@ -69,7 +73,7 @@ def create_hgrc_file(app, repository):
|
||||
# empty directories. This is not currently used because it is not supported
|
||||
# in the Mercurial API.
|
||||
repo_path = repository.repo_path(app)
|
||||
hgrc_path = os.path.join(repo_path, '.hg', 'hgrc')
|
||||
hgrc_path = get_hgrc_path(repo_path)
|
||||
with open(hgrc_path, 'w') as fp:
|
||||
fp.write('[paths]\n')
|
||||
fp.write('default = .\n')
|
||||
@@ -133,7 +137,7 @@ def get_reversed_changelog_changesets(repo):
|
||||
|
||||
def get_revision_label(app, repository, changeset_revision, include_date=True, include_hash=True):
|
||||
"""
|
||||
Return a string consisting of the human read-able changeset rev and the changeset revision string
|
||||
Return a string consisting of the human readable changeset rev and the changeset revision string
|
||||
which includes the revision date if the receive include_date is True.
|
||||
"""
|
||||
repo = get_repo_for_repository(app, repository=repository)
|
||||
@@ -188,7 +192,7 @@ def get_revision_label_from_ctx(ctx, include_date=True, include_hash=True):
|
||||
if include_hash:
|
||||
return '%s:%s' % (str(ctx.rev()), str(ctx))
|
||||
else:
|
||||
return '%s' % str(ctx.rev())
|
||||
return str(ctx.rev())
|
||||
|
||||
|
||||
def get_rev_label_from_changeset_revision(repo, changeset_revision, include_date=True, include_hash=True):
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import re
|
||||
|
||||
from markupsafe import escape
|
||||
from six.moves import configparser
|
||||
from sqlalchemy import false
|
||||
from sqlalchemy.sql import select
|
||||
|
||||
@@ -10,7 +11,6 @@ import tool_shed.dependencies.repository
|
||||
from galaxy import util
|
||||
from galaxy import web
|
||||
from galaxy.tool_shed.util.repository_util import (
|
||||
change_repository_name_in_hgrc_file,
|
||||
check_for_updates,
|
||||
check_or_update_tool_shed_status_for_installed_repository,
|
||||
create_or_update_tool_shed_repository,
|
||||
@@ -46,6 +46,7 @@ from galaxy.util.tool_shed import common_util
|
||||
from tool_shed.util.hg_util import (
|
||||
changeset2rev,
|
||||
create_hgrc_file,
|
||||
get_hgrc_path,
|
||||
init_repository,
|
||||
)
|
||||
from tool_shed.util.metadata_util import (
|
||||
@@ -401,6 +402,14 @@ def handle_role_associations(app, role, repository, **kwd):
|
||||
return associations_dict
|
||||
|
||||
|
||||
def change_repository_name_in_hgrc_file(hgrc_file, new_name):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(hgrc_file)
|
||||
config.set('web', 'name', new_name)
|
||||
with open(hgrc_file, 'wb') as fh:
|
||||
config.write(fh)
|
||||
|
||||
|
||||
def update_repository(app, trans, id, **kwds):
|
||||
"""Update an existing ToolShed repository"""
|
||||
message = None
|
||||
@@ -457,7 +466,7 @@ def update_repository(app, trans, id, **kwds):
|
||||
trans.app.hgweb_config_manager.change_entry(old_lhs, new_lhs, repo_dir)
|
||||
|
||||
# Change the entry in the repository's hgrc file.
|
||||
hgrc_file = os.path.join(repo_dir, '.hg', 'hgrc')
|
||||
hgrc_file = get_hgrc_path(repo_dir)
|
||||
change_repository_name_in_hgrc_file(hgrc_file, kwds['name'])
|
||||
|
||||
# Rename the repository's admin role to match the new repository name.
|
||||
|
||||
@@ -280,17 +280,18 @@ class Repository(Dictifiable):
|
||||
if username not in allow_push:
|
||||
allow_push.append(username)
|
||||
allow_push = '%s\n' % ','.join(allow_push)
|
||||
repo = hg_util.get_repo_for_repository(app, repository=self)
|
||||
# Why doesn't the following work?
|
||||
# repo.ui.setconfig( 'web', 'allow_push', allow_push )
|
||||
lines = repo.opener('hgrc', 'rb').readlines()
|
||||
fp = repo.opener('hgrc', 'wb')
|
||||
for line in lines:
|
||||
if line.startswith('allow_push'):
|
||||
fp.write('allow_push = %s' % allow_push)
|
||||
else:
|
||||
fp.write(line)
|
||||
fp.close()
|
||||
# repo.ui.setconfig('web', 'allow_push', allow_push)
|
||||
repo_dir = self.repo_path(app)
|
||||
hgrc_file = hg_util.get_hgrc_path(repo_dir)
|
||||
with open(hgrc_file, 'rb') as fh:
|
||||
lines = fh.readlines()
|
||||
with open(hgrc_file, 'wb') as fh:
|
||||
for line in lines:
|
||||
if line.startswith('allow_push'):
|
||||
fh.write('allow_push = %s' % allow_push)
|
||||
else:
|
||||
fh.write(line)
|
||||
|
||||
def tip(self, app):
|
||||
repo = hg_util.get_repo_for_repository(app, repository=self)
|
||||
|
||||
Reference in New Issue
Block a user