Exemplo n.º 1
0
 def __getitem__(self, key):
     key = self._metadata_rewrites.get(key, key)
     if key in self._wipes:
         raise KeyError(self, key)
     if key == "contents":
         data = generate_contents(self._parent._get_path(self._pkg))
         object.__setattr__(self, "contents", data)
     elif key == "environment":
         data = self.xpak.get("environment.bz2")
         if data is None:
             data = data_source(self.xpak.get("environment"), mutable=True)
             if data is None:
                 raise KeyError(
                     "environment.bz2 not found in xpak segment, "
                     "malformed binpkg?")
         else:
             data = data_source(compression.decompress_data('bzip2', data),
                                mutable=True)
     elif key == "ebuild":
         data = self.xpak.get(
             f"{self._pkg.package}-{self._pkg.fullver}.ebuild", "")
         data = data_source(data)
     else:
         try:
             data = self.xpak[key]
         except KeyError:
             if key == '_eclasses_':
                 # hack...
                 data = {}
             else:
                 data = ''
     return data
Exemplo n.º 2
0
    def get_metadata_xml(herds=(), maintainers=(), local_use=(), longdescription=None):
        hs = ms = us = ls = ""
        if herds:
            hs = "<herd>%s</herd>\n" % "</herd><herd>".join(herds)
        if maintainers:
            ms = []
            for x in maintainers:
                ms.append("<email>%s</email>" % x[0])
                if len(x) > 1:
                    ms[-1] = "%s\n<name>%s</name>" % (ms[-1], x[1])
            ms = "<maintainer>%s</maintainer>\n" % \
                "</maintainer><maintainer>".join(ms)
        if local_use:
            us = ['<use>']
            for flag in local_use:
                us.append('<flag name="%s">use flag description</flag>' % flag)
            us.append('</use>')
            us = '\n'.join(us)
        if longdescription:
            ls = "<longdescription>%s</longdescription>\n" % longdescription
        s = \
"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
%s%s%s%s</pkgmetadata>""" % (hs, ms, us, ls)
        return repo_objs.MetadataXml(data_source(s.encode('utf-8')))
Exemplo n.º 3
0
    def test_init(self):
        base.test_init(self)
        mkobj = self.make_obj
        o = mkobj(__file__)
        raw_data = open(__file__).read()
        self.assertEqual(o.data.text_fileobj().read(), raw_data)
        o = mkobj("/bin/this-file-should-not-exist-nor-be-read",
            data=data_source(raw_data))
        self.assertEqual(o.data.text_fileobj().read(), raw_data)
        keys = o.chksums.keys()
        self.assertEqual([o.chksums[x] for x in keys],
            list(get_chksums(data_source(raw_data), *keys)))

        chksums = dict(o.chksums.iteritems())
        self.assertEqual(sorted(mkobj(chksums=chksums).chksums.iteritems()),
            sorted(chksums.iteritems()))
Exemplo n.º 4
0
    def get_metadata_xml(maintainers=(),
                         comments=(),
                         local_use={},
                         longdescription=None,
                         maint_type=None):
        cs = '\n'.join(comments)
        ms = us = ls = ""
        if maintainers:
            ms = []
            for x in maintainers:
                ms.append(f"<email>{x[0]}</email>")
                if len(x) > 1:
                    ms[-1] += f"\n<name>{x[1]}</name>"
                if len(x) > 2:
                    ms[-1] += f"\n<description>{x[2]}</description>"
                if len(x) > 3:
                    raise ValueError('maintainer data has too many fields')
            maint_type = (f'type="{maint_type}"'
                          if maint_type is not None else '')
            ms = '\n'.join(f'<maintainer {maint_type}>{x}</maintainer>'
                           for x in ms)
        if local_use:
            us = ['<use>']
            for flag, desc in local_use.items():
                us.append(f'<flag name="{flag}">{desc}</flag>')
            us.append('</use>')
            us = '\n'.join(us)
        if longdescription:
            ls = f"<longdescription>{longdescription}</longdescription>\n"
        s = \
f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
{cs}{ms}{us}{ls}</pkgmetadata>"""
        return repo_objs.MetadataXml(data_source(s.encode('utf-8')))
Exemplo n.º 5
0
    def get_metadata_xml(herds=(), maintainers=(), local_use={}, longdescription=None):
        hs = ms = us = ls = ""
        if herds:
            hs = "<herd>%s</herd>\n" % "</herd><herd>".join(herds)
        if maintainers:
            ms = []
            for x in maintainers:
                ms.append("<email>%s</email>" % x[0])
                if len(x) > 1:
                    ms[-1] = "%s\n<name>%s</name>" % (ms[-1], x[1])
            ms = "<maintainer>%s</maintainer>\n" % "</maintainer><maintainer>".join(ms)
        if local_use:
            us = ["<use>"]
            for flag, desc in local_use.iteritems():
                us.append('<flag name="%s">%s</flag>' % (flag, desc))
            us.append("</use>")
            us = "\n".join(us)
        if longdescription:
            ls = "<longdescription>%s</longdescription>\n" % longdescription
        s = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
%s%s%s%s</pkgmetadata>""" % (
            hs,
            ms,
            us,
            ls,
        )
        return repo_objs.MetadataXml(data_source(s.encode("utf-8")))
Exemplo n.º 6
0
    def test_init(self):
        base.test_init(self)
        mkobj = self.make_obj
        o = mkobj(__file__)
        with open(__file__) as f:
            raw_data = f.read()
        self.assertEqual(o.data.text_fileobj().read(), raw_data)
        o = mkobj("/bin/this-file-should-not-exist-nor-be-read",
            data=data_source(raw_data))
        self.assertEqual(o.data.text_fileobj().read(), raw_data)
        keys = list(o.chksums.keys())
        self.assertEqual([o.chksums[x] for x in keys],
            list(get_chksums(data_source(raw_data), *keys)))

        chksums = dict(iter(o.chksums.items()))
        self.assertEqual(sorted(mkobj(chksums=chksums).chksums.items()),
            sorted(chksums.items()))
Exemplo n.º 7
0
    def test_transfer_to_data_source(self):
        data = self._mk_data()
        reader = self.get_obj(data=data)
        if self.supports_mutable:
            writer = self.get_obj(data='', mutable=True)
        else:
            writer = data_source.data_source('', mutable=True)
        reader.transfer_to_data_source(writer)

        self.assertContents(reader, writer)
Exemplo n.º 8
0
    def test_transfer_to_data_source(self):
        data = self._mk_data()
        reader = self.get_obj(data=data)
        if self.supports_mutable:
            writer = self.get_obj(data='', mutable=True)
        else:
            writer = data_source.data_source('', mutable=True)
        reader.transfer_to_data_source(writer)

        self.assertContents(reader, writer)
Exemplo n.º 9
0
    def test_transfer_data_between_files(self):
        data = self._mk_data()
        reader = self.get_obj(data=data)
        if self.supports_mutable:
            writer = self.get_obj(data='', mutable=True)
        else:
            writer = data_source.data_source('', mutable=True)

        reader_f, writer_f = reader.bytes_fileobj(), writer.bytes_fileobj(True)
        data_source.transfer_between_files(reader_f, writer_f)
        reader_f.close(), writer_f.close()

        self.assertContents(reader, writer)
Exemplo n.º 10
0
    def test_transfer_data_between_files(self):
        data = self._mk_data()
        reader = self.get_obj(data=data)
        if self.supports_mutable:
            writer = self.get_obj(data='', mutable=True)
        else:
            writer = data_source.data_source('', mutable=True)

        reader_f, writer_f = reader.bytes_fileobj(), writer.bytes_fileobj(True)
        data_source.transfer_between_files(reader_f, writer_f)
        reader_f.close(), writer_f.close()

        self.assertContents(reader, writer)
Exemplo n.º 11
0
    def get_metadata_xml(herds=(), maintainers=(), longdescription=None):
        hs, ms, ls = "", "", ""
        if herds:
            hs = "<herd>%s</herd>\n" % "</herd><herd>".join(herds)
        if maintainers:
            ms = []
            for x in maintainers:
                ms.append("<email>%s</email>" % x[0])
                if len(x) > 1:
                    ms[-1] = "%s\n<name>%s</name>" % (ms[-1], x[1])
            ms = "<maintainer>%s</maintainer>\n" % \
                "</maintainer><maintainer>".join(ms)
        if longdescription:
            ls = "<longdescription>%s</longdescription>\n" % longdescription
        s = \
"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
%s%s%s</pkgmetadata>""" % (hs, ms, ls)
        return repo_objs.MetadataXml(data_source(s.encode('utf-8')))
Exemplo n.º 12
0
    def get_metadata_xml(maintainers=(), local_use={}, longdescription=None):
        hs = ms = us = ls = ""
        if maintainers:
            ms = []
            for x in maintainers:
                ms.append(f"<email>{x[0]}</email>")
                if len(x) > 1:
                    ms[-1] = f"{ms[-1]}\n<name>{x[1]}</name>"
            ms = "<maintainer>%s</maintainer>\n" % "</maintainer><maintainer>".join(ms)
        if local_use:
            us = ['<use>']
            for flag, desc in local_use.items():
                us.append(f'<flag name="{flag}">{desc}</flag>')
            us.append('</use>')
            us = '\n'.join(us)
        if longdescription:
            ls = f"<longdescription>{longdescription}</longdescription>\n"
        s = \
f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
{hs}{ms}{us}{ls}</pkgmetadata>"""
        return repo_objs.MetadataXml(data_source(s.encode('utf-8')))
Exemplo n.º 13
0
    def get_metadata_xml(maintainers=(), local_use={}, longdescription=None):
        hs = ms = us = ls = ""
        if maintainers:
            ms = []
            for x in maintainers:
                ms.append(f"<email>{x[0]}</email>")
                if len(x) > 1:
                    ms[-1] = f"{ms[-1]}\n<name>{x[1]}</name>"
            ms = "<maintainer>%s</maintainer>\n" % "</maintainer><maintainer>".join(
                ms)
        if local_use:
            us = ['<use>']
            for flag, desc in local_use.items():
                us.append(f'<flag name="{flag}">{desc}</flag>')
            us.append('</use>')
            us = '\n'.join(us)
        if longdescription:
            ls = f"<longdescription>{longdescription}</longdescription>\n"
        s = \
f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
{hs}{ms}{us}{ls}</pkgmetadata>"""
        return repo_objs.MetadataXml(data_source(s.encode('utf-8')))
Exemplo n.º 14
0
def _callback(chf):
    return handlers[chf](data_source.data_source(data))
Exemplo n.º 15
0
    def get_projects_xml(s=None):
        default_s = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE projects SYSTEM "http://www.gentoo.org/dtd/projects.dtd">
<projects>
  <project>
    <email>[email protected]</email>
    <name>Project with no members</name>
    <url>https://projects.example.com/nomembers</url>
    <description>Here is the description</description>
  </project>
  <project>
    <email>[email protected]</email>
    <name>Project with no lead</name>
    <url>https://projects.example.com/nolead</url>
    <description>Here is the description</description>
    <member>
      <email>[email protected]</email>
      <name>Full Dev</name>
      <role>Somebody</role>
    </member>
    <member>
      <email>[email protected]</email>
    </member>
  </project>
  <project>
    <email>[email protected]</email>
    <name>Project with a lead</name>
    <url>https://projects.example.com/lead</url>
    <description>Here is the description</description>
    <member>
      <email>[email protected]</email>
      <name>Full Dev</name>
      <role>Somebody</role>
    </member>
    <member is-lead="1">
      <email>[email protected]</email>
    </member>
  </project>
  <project>
    <email>[email protected]</email>
    <name>Project with non-recursive subprojects</name>
    <url>https://projects.example.com/subprojects</url>
    <description>Here is the description</description>
    <member>
      <email>[email protected]</email>
      <name>Full Dev</name>
      <role>Somebody</role>
    </member>
    <member is-lead="1">
      <email>[email protected]</email>
    </member>
    <subproject ref="*****@*****.**"/>
    <subproject ref="*****@*****.**"/>
  </project>
  <project>
    <email>[email protected]</email>
    <name>Project with recursive subprojects</name>
    <url>https://projects.example.com/recursive-subprojects</url>
    <description>Here is the description</description>
    <member>
      <email>[email protected]</email>
      <name>Full Dev</name>
      <role>Somebody</role>
    </member>
    <member>
      <!-- this one is common -->
      <email>[email protected]</email>
    </member>
    <member is-lead="1">
      <email>[email protected]</email>
    </member>
    <subproject ref="*****@*****.**" inherit-members="1"/>
    <subproject ref="*****@*****.**"/>
  </project>
  <project>
    <email>[email protected]</email>
    <name>Project with double recursion</name>
    <url>https://projects.example.com/super-recursive-subprojects</url>
    <description>Here is the description</description>
    <member>
      <email>[email protected]</email>
      <name>Full Dev</name>
      <role>Somebody</role>
    </member>
    <member is-lead="1">
      <!-- this one is common -->
      <email>[email protected]</email>
    </member>
    <member>
      <email>[email protected]</email>
    </member>
    <subproject ref="*****@*****.**" inherit-members="1"/>
  </project>
</projects>"""
        if s is None:
            s = default_s
        return repo_objs.ProjectsXml(data_source(s.encode('utf-8')))
Exemplo n.º 16
0
 def get_obj(self, data="foonani", mutable=False):
     return data_source.data_source(data, mutable=mutable)
Exemplo n.º 17
0
 def test_data_source_check(self):
     self.assertEqual(self.chf(local_source(self.fn)), self.expected_long)
     self.assertEqual(
         self.chf(data_source(fileutils.readfile_ascii(self.fn))), self.expected_long)
Exemplo n.º 18
0
 def environment(self):
     data = self._get_ebuild_environment()
     return data_source.data_source(data, mutable=False)
Exemplo n.º 19
0
def _callback(chf):
    return handlers[chf](data_source.data_source(data))
Exemplo n.º 20
0
 def test_data_source_check(self):
     assert self.chf(local_source(self.fn)) == self.expected_long
     assert self.chf(data_source(fileutils.readfile_ascii(
         self.fn))) == self.expected_long
Exemplo n.º 21
0
 def test_data_source_check(self):
     self.assertEqual(self.chf(local_source(self.fn)), self.expected_long)
     self.assertEqual(
         self.chf(data_source(fileutils.readfile_ascii(self.fn))),
         self.expected_long)
Exemplo n.º 22
0
 def get_obj(self, data="foonani", mutable=False):
     return data_source.data_source(data, mutable=mutable)
Exemplo n.º 23
0
 def _src(self, cpv, eapi_str):
     return data_source(f'EAPI={eapi_str}')
Exemplo n.º 24
0
 def _src(self, cpv, eapi_str):
     return data_source(f'EAPI={eapi_str}')