#113 write-repo-file: support HTTP(S) URLs to composes
Merged 3 years ago by lsedlar. Opened 3 years ago by ktdreyer.
ktdreyer/compose-utils write-repo-http  into  master

file modified
+15 -2
@@ -30,6 +30,15 @@ 

      return url_prefix + path[len(strip_prefix) :]

  

  

+ def is_url(path):

+     """ Return True if this an HTTP(s) URL, False otherwise """

+     if path.startswith('http://'):

+         return True

+     if path.startswith('https://'):

+         return True

+     return False

+ 

+ 

  def emit(compose, opts, variant, output, content_type="repository"):

      """Print configuration for a single repository into output."""

      paths = getattr(variant.paths, content_type)
@@ -74,14 +83,18 @@ 

      if opts.translate:

          baseurl = translate(baseurl, *opts.translate)

      else:

-         baseurl = "file://" + baseurl

+         if not is_url(baseurl):

+             baseurl = "file://" + baseurl

  

      content = REPO.format(name=name, enabled=enabled, baseurl=baseurl)

      print(content, file=output)

  

  

  def run(opts, output):

-     compose = productmd.Compose(os.path.realpath(opts.COMPOSE))

+     path = opts.COMPOSE

+     if not is_url(path):

+         path = os.path.realpath(path)

+     compose = productmd.Compose(path)

  

      def by_uid(variant):

          return variant.uid

file modified
+5
@@ -100,3 +100,8 @@ 

          self.assertIn(

              "/Client/$basearch/os does not start with /foo/bar.\n", mock_err.getvalue()

          )

+ 

+     def test_is_url(self):

+         self.assertTrue(repo_file.is_url('http://example.com/foobar'))

+         self.assertTrue(repo_file.is_url('https://example.com/foobar'))

+         self.assertFalse(repo_file.is_url('/path/to/foobar'))

Handle HTTP or HTTPS URLs to composes.

(Also, wow we are using pytest now! I should have rewritten tests/test_repo_file.py to use simple asserts!)

Jenkins says ImportError: No module named 'rpm', and I can reproduce that on my computer also.

The failure is indeed unrelated to this change. It should be fixed by #114. Please rebase your patch on top of latest master and I'll merge it.

rebased onto 775fdad

3 years ago

Thanks. I rebased and re-pushed.

Pull-Request has been merged by lsedlar

3 years ago