Skip to content

Commit

Permalink
dist-git: refresh pyrpkg.Commands after import_srpm
Browse files Browse the repository at this point in the history
in case of importing, the content of directory in `reponame`
changes. To update the state of `Commands` class isn't an easy
process - look how much logic pyrpkg.cli.cliClient.load_cmd has
and the logic is written for context in cliClient, not for Commands
which we are using. Considering this wouldn't be an easy task for
pyrpkg to implement, we can refresh the Commands class after every
import - even if it is not elegant
note: if https://pagure.io/rpkg/issue/690 is resolved, you may delete
this
  • Loading branch information
nikromen committed Jun 8, 2023
1 parent 49aa87c commit 8ff37ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
54 changes: 34 additions & 20 deletions dist-git/copr_dist_git/package_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,7 @@ def cleanup_repo(repo_path):
['git', 'rm', '-r'] + to_remove)


def import_package(opts, namespace, branches, srpm_path, pkg_name):
"""
Import package into a DistGit repo for the given branches.
:param Munch opts: service configuration
:param str namespace: repo name prefix
:param list(str) branches: list of branch names to import into
:param str srpm_path: path to the srpm file
:return Munch: resulting import data:
(branch_commits, reponame, pkg_name)
"""

reponame = "{}/{}".format(namespace, pkg_name)
setup_git_repo(reponame, branches)

repo_dir = tempfile.mkdtemp()
log.debug("repo_dir: {}".format(repo_dir))

def _load_commands(opts, repo_name, repo_dir):
# use rpkg lib to import the source rpm
commands = Commands(path=repo_dir,
lookaside="",
Expand All @@ -181,12 +163,35 @@ def import_package(opts, namespace, branches, srpm_path, pkg_name):
# rpkg gets module_name as a basename of git url
# we use module_name as "username/projectname/package_name"
# basename is not working here - so I'm setting it manually
commands.repo_name = reponame
commands.repo_name = repo_name

# rpkg calls upload.cgi script on the dist git server
# here, I just copy the source files manually with custom function
# I also add one parameter "repo_dir" to that function with this hack
commands.lookasidecache.upload = types.MethodType(my_upload_fabric(opts), repo_dir)
return commands


def import_package(opts, namespace, branches, srpm_path, pkg_name):
"""
Import package into a DistGit repo for the given branches.
:param Munch opts: service configuration
:param str namespace: repo name prefix
:param list(str) branches: list of branch names to import into
:param str srpm_path: path to the srpm file
:return Munch: resulting import data:
(branch_commits, reponame, pkg_name)
"""

reponame = "{}/{}".format(namespace, pkg_name)
setup_git_repo(reponame, branches)

repo_dir = tempfile.mkdtemp()
log.debug("repo_dir: {}".format(repo_dir))

commands = _load_commands(opts, reponame, repo_dir)

try:
log.debug("clone the pkg repository into repo_dir directory")
Expand Down Expand Up @@ -218,6 +223,15 @@ def import_package(opts, namespace, branches, srpm_path, pkg_name):
try:
if not branch_commits:
upload_files = commands.import_srpm(srpm_path)
# in case of importing, the content of directory in `reponame`
# changes. To update the state of `Commands` class isn't an easy
# process - look how much logic pyrpkg.cli.cliClient.load_cmd has
# and the logic is written for context in cliClient, not for Commands
# which we are using. Considering this wouldn't be an easy task for
# pyrpkg to implement, we can refresh the Commands class after every
# import - even if it is not elegant
# note: if https://pagure.io/rpkg/issue/690 is resolved, you may delete this
commands = _load_commands(opts, reponame, repo_dir)
if upload_files:
commands.upload(upload_files, replace=True)
try:
Expand Down
2 changes: 0 additions & 2 deletions dist-git/tests/test_crazy_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def commit_to_branches(self, to_branches, opts, version):
def setup_method(self, method):
srpm_cache = {}

@pytest.mark.skip(reason="Remove the skip once python-rpkg is repared (correct version is 1.65)")
def test_merged_everything(self, initial_commit_everywhere, mc_setup_git_repo):
branches, opts, v1_hash = initial_commit_everywhere
origin, all_branches, middle_branches, border_branches = branches
Expand All @@ -209,7 +208,6 @@ def test_merged_everything(self, initial_commit_everywhere, mc_setup_git_repo):
assert v3_hash != v1_hash
assert v3_hash != v2_hash

@pytest.mark.skip(reason="Remove the skip once python-rpkg is repared (correct version is 1.65)")
def test_diverge_middle_branches(self, initial_commit_everywhere, mc_setup_git_repo):
branches, opts, v1_hash = initial_commit_everywhere
origin, all_branches, middle_branches, border_branches = branches
Expand Down

0 comments on commit 8ff37ae

Please sign in to comment.