#2217 Fix LGTM.com errors
Merged 2 months ago by praiskup. Opened 2 months ago by frostyx.
copr/ frostyx/copr fix-lgtm-errors  into  main

@@ -29,7 +29,7 @@ 

      logger = create_file_logger("run.check_signed_rpms_in_pkg_dir",

                                  "/tmp/copr_check_signed_rpms.log")

      try:

-         sign_rpms_in_dir(user, project, pkg_dir, opts, log=logger)

+         sign_rpms_in_dir(user, project, pkg_dir, chroot_dir, opts, log=logger)

          log.info("running createrepo for {}".format(pkg_dir))

          call_copr_repo(directory=chroot_dir, devel=devel, logger=log)

      except Exception as err:

@@ -7,9 +7,9 @@ 

  

  

  def print_invalid_format(chroot_name):

-     print(

-         "{0} - invalid chroot format, must be '{release}-{version}-{arch}'."

-             .format(chroot_name))

+     msg = ("{0} - invalid chroot format, "

+            "must be '{{release}}-{{version}}-{{arch}}'.")

+     print(msg.format(chroot_name))

  

  

  def print_already_exists(chroot_name):
@@ -24,10 +24,15 @@ 

                             comment=None):

      """Creates a mock chroot in DB"""

      for chroot_name in chroot_names:

-         if not branch:

-             branch = chroot_to_branch(chroot_name)

-         branch_object = coprs_logic.BranchesLogic.get_or_create(branch)

          try:

+             # Just a validation that chroot name is in an expected format

+             # Otherwise we get traceback when determining its branch value

+             coprs_logic.MockChrootsLogic.tuple_from_name(chroot_name)

+ 

+             if not branch:

+                 branch = chroot_to_branch(chroot_name)

+             branch_object = coprs_logic.BranchesLogic.get_or_create(branch)

+ 

              chroot = coprs_logic.MockChrootsLogic.add(chroot_name)

              chroot.distgit_branch = branch_object

              chroot.is_active = activated

@@ -40,7 +40,7 @@ 

  

  class CoprSearchRelatedData(object):

      def get_search_related_copr_id(self):

-         raise "Not Implemented"

+         raise NotImplementedError

  

  

  class _UserPublic(db.Model, helpers.Serializer):
@@ -257,7 +257,7 @@ 

  _group_unique_where = text("deleted is not true and group_id is not null")

  _user_unique_where = text("deleted is not true and group_id is null")

  

- class _CoprPublic(db.Model, helpers.Serializer, CoprSearchRelatedData):

+ class _CoprPublic(db.Model, helpers.Serializer):

      """

      Represents public part of a single copr (personal repo with builds, mock

      chroots, etc.).
@@ -364,7 +364,7 @@ 

      scm_api_auth_json = db.Column(db.Text)

  

  

- class Copr(db.Model, helpers.Serializer):

+ class Copr(db.Model, helpers.Serializer, CoprSearchRelatedData):

      """

      Represents private a single copr (personal repo with builds, mock chroots,

      etc.).

@@ -246,7 +246,7 @@ 

          try:

              package = PackagesLogic.get(copr.main_dir.id, package_name)[0]

          except IndexError:

-             flask.flash("Package {package_name} does not exist in copr_dir {copr_dir}."

+             flask.flash("Package {0} does not exist in copr_dir {1}."

                          .format(package_name, copr.main_dir.full_name))

              return flask.redirect(url_on_success) # should be url_on_fail

  

file removed
-144
@@ -1,144 +0,0 @@ 

- #!/usr/bin/python

- import requests

- import json

- import xmlrpclib

- from pip._vendor.packaging.version import parse

- import subprocess

- import argparse

- import time

- import os

- from copr import create_client2_from_params

- from copr import CoprClient

- import json

- 

- URL_PATTERN = 'https://pypi.python.org/pypi/{package}/json'

- CONFIG = os.path.join(os.path.expanduser("~"), ".config/copr")

- 

- COPR_URL = "https://copr.fedorainfracloud.org/"

- USER = "@copr"

- COPR = "PyPI2"

- 

- cl = CoprClient.create_from_file_config(CONFIG)

- 

- parser = argparse.ArgumentParser(prog = "pypi")

- parser.add_argument("-s", "--submit-pypi-modules", dest="submit_pypi_modules", metavar='PYTHON_VERSION', action="store")

- parser.add_argument("-u", "--submit-unbuilt-pypi-modules", dest="submit_unbuilt_pypi_modules", metavar='PYTHON_VERSION', action="store")

- parser.add_argument("-p", "--parse-succeeded-packages", dest="parse_succeeded_packages", action="store_true")

- parser.add_argument("-o", "--parse-succeeded-packages-v1client", dest="parse_succeeded_packages_v1client", action="store_true")

- args = parser.parse_args()

- 

- 

- def create_package_name(module_name):

-     return "python-{}".format(module_name.replace(".", "-"))

- 

- 

- #NOT USED

- def get_version(package, url_pattern=URL_PATTERN):

-     """Return version of package on pypi.python.org using json."""

-     req = requests.get(url_pattern.format(package=package))

-     version = parse('0')

-     if req.status_code == requests.codes.ok:

-         j = json.loads(req.text.encode(req.encoding))

-         if 'releases' in j:

-             releases = j['releases']

-             for release in releases:

-                 ver = parse(release)

-                 if not ver.is_prerelease:

-                     version = max(version, ver)

-     return version

- 

- 

- def submit_build(copr_name, module_name, python_version):

-     command = ["/usr/bin/copr-cli", "--config", CONFIG,

-                "buildpypi", copr_name, "--packagename", module_name,

-                "--nowait",

-                "--pythonversions", python_version]

-     subprocess.call(command)

- 

- 

- def get_all_pypi_modules():

-     client = xmlrpclib.ServerProxy('https://pypi.python.org/pypi')

-     modules = client.list_packages()

-     return modules

- 

- 

- def submit_all_pypi_modules(python_version):

-     for module in get_all_pypi_modules(python_version):

-         print("Submitting module {0}".format(module))

-         submit_build("{}/{}".format(USER, COPR), module, python_version)

-         time.sleep(4)

- 

- 

- def submit_unbuilt_pypi_modules(python_version):

-     succeeded_modules = get_succeeded_modules(python_version)

-     for module in get_all_pypi_modules():

-         if module in succeeded_modules:

-             print("PyPI module '{0}' already built. Skipping.".format(module))

-             continue

-         print("Submitting module {0}".format(module))

-         submit_build("{}/{}".format(USER, COPR), module, python_version)

-         time.sleep(4)

- 

- 

- def parse_succeeded_packages():

-     """

-     Print a list of succeeded packages from the USER/COPR repository, one package per line

-     If you are looking into this code because you think, that the script froze, be cool. It is just very slow, because

-     it iterates 100 results from copr-fe per one result.

-     """

-     cl = create_client2_from_params(root_url=COPR_URL)

-     copr = filter(lambda copr: copr.owner == USER, cl.projects.get_list(name=COPR))[0]

-     packages = {}

- 

-     limit = 100

-     offset = 0

-     while True:

-         # @WORKAROUND This code is so ugly because we do not have support for Package resource in api_2 yet.

-         # This is why we list all builds and examine their packages.

-         builds = cl.builds.get_list(project_id=copr.id, limit=limit, offset=offset)

-         if not list(builds):

-             break

- 

-         for build in filter(lambda x: x.package_name and x.state == "succeeded", builds):

-             packages[build.package_name] = build.state

-         offset += limit

- 

-     for package in packages:

-         print(package)

- 

- 

- def parse_succeeded_packages_v1client():

-     for package in get_succeeded_packages():

-         print(package.name)

- 

- 

- def get_succeeded_packages():

-     succeeded_packages = []

-     result = cl.get_packages_list(projectname=COPR, ownername=USER, with_latest_succeeded_build=True)

-     for package in result.packages_list:

-         if package.latest_succeeded_build:

-             succeeded_packages.append(package)

-     return succeeded_packages

- 

- 

- def get_succeeded_modules(python_version):

-     succeeded_modules = []

-     for package in get_succeeded_packages():

-         source_json = json.loads(package.source_json)

-         if python_version in source_json['python_versions']:

-             succeeded_modules.append(json.loads(package.source_json)['pypi_package_name'])

-     return succeeded_modules

- 

- 

- if __name__ == "__main__":

-     if args.submit_pypi_modules:

-         submit_all_pypi_modules(args.submit_pypi_modules)

-     elif args.parse_succeeded_packages:

-         parse_succeeded_packages()

-     elif args.parse_succeeded_packages_v1client:

-         parse_succeeded_packages_v1client()

-     elif args.submit_unbuilt_pypi_modules:

-         submit_unbuilt_pypi_modules(args.submit_unbuilt_pypi_modules)

-     else:

-         print("Specify action: See --help")

-         parser.print_usage()

file removed
-37
@@ -1,37 +0,0 @@ 

- #!/usr/bin/python

- import os

- import time

- from subprocess import PIPE, Popen, call

- 

- 

- SLEEP = 20

- CONFIG = os.path.join(os.path.expanduser("~"), ".config/copr")

- USER = "@rubygems"

- COPR = "rubygems"

- 

- 

- def all_gems():

-     # Require `rubygems` package

-     cmd = ["gem", "search"]

-     proc = Popen(cmd, stdout=PIPE, stderr=PIPE)

-     output, error = proc.communicate()

-     return [x.split()[0] for x in output.split("\n")[:-1]]

- 

- 

- def submit_build(copr, gem):

-     command = ["/usr/bin/copr-cli", "--config", CONFIG,

-                "buildgem", copr, "--gem", gem, "--nowait", "--background"]

-     call(command)

- 

- 

- def main():

-     for gem in all_gems():

-         if gem <= "fotki-export":

-             continue

-         print("Submitting gem {0}".format(gem))

-         submit_build("{}/{}".format(USER, COPR), gem)

-         print("")

-         time.sleep(SLEEP)

- 

- if __name__ == "__main__":

-     main()

I went through the 16 errors that LGTM.com found, see
https://lgtm.com/projects/g/fedora-copr/copr/?mode=list&severity=error

Some of them were valid errors worth fixing.

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

6 new commits added

  • backend: the sign_rpms_in_dir function expects one more parameter
  • frontend: raise a proper exception
  • misc: remove unused scripts to interact with PyPI and RubyGems
  • frontend: validate the chroot name to avoid traceback
  • frontend: escape curly braces in the formatted string
  • frontend: fix string formatting, we pass positional args, not kwargs
2 months ago

Build succeeded.

Pull-Request has been merged by praiskup

2 months ago