def test_ParseIpsPkgContentsLineLink(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_1 expected = { 'pkgnames': ['SUNWsystem-core-os'], 'group': None, 'target': './usr/bin', 'owner': None, 'path': '/bin', 'line': PKGCONTENT_LINE_1, 'type': 's', 'mode': None, } self.assertEquals(expected, spi._ParseIpsPkgContentsLine(line))
def test_ParseIpsPkgContentsLineDir(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_2 expected = { 'pkgnames': ['SUNWsystem-core-os'], 'group': 'sys', 'target': None, 'owner': 'root', 'path': '/dev', 'line': PKGCONTENT_LINE_2, 'type': 'd', 'mode': '0755', } self.assertEquals(expected, spi._ParseIpsPkgContentsLine(line))
def test_ParseIpsPkgContentsLineFile(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_4 expected = { 'pkgnames': ['SUNWsystem-library'], 'group': 'bin', 'target': None, 'owner': 'root', 'path': '/lib/libc.so.1', 'line': PKGCONTENT_LINE_4, 'type': 'f', 'mode': '0755', } self.assertEquals(expected, spi._ParseIpsPkgContentsLine(line))
def test_ParseIpsPkgContentsLineHardlink(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_3 expected = { 'pkgnames': ['SUNWsystem-core-os'], 'group': None, 'target': './platform_SUNW,UltraSPARC-IIi-Netract.xml', 'owner': None, 'path': '/etc/svc/profile/platform_SUNW,UltraSPARC-IIe-NetraCT-40.xml', 'line': PKGCONTENT_LINE_3, 'type': 'l', 'mode': None, } self.assertEquals(expected, spi._ParseIpsPkgContentsLine(line))
def test_ParsePkgContents(self): spi = system_pkgmap.Indexer() srv4_stream = (PKGMAP_LINE_1, PKGMAP_LINE_2, PKGMAP_LINE_3, PKGMAP_LINE_4) ips_stream = (PKGCONTENT_LINE_1, PKGCONTENT_LINE_2, PKGCONTENT_LINE_3, PKGCONTENT_LINE_4) self.assertEqual( 4, len( spi._ParsePkgContents(srv4_stream, spi._ParseSrv4PkgmapLine, False))) self.assertEqual( 4, len( spi._ParsePkgContents(ips_stream, spi._ParseIpsPkgContentsLine, False)))
def RefreshDatabase(self): # Using the same stuff pkgdb is using. logging.warning( "Refreshing the database. It may take a long time, please be patient." ) logging.warning("If you need a way to make it faster, please see:") logging.warning("http://wiki.opencsw.org/checkpkg#toc5") infile_contents = common_constants.DEFAULT_INSTALL_CONTENTS_FILE infile_pkginfo = None logging.debug("Indexing.") spi = system_pkgmap.Indexer(None, infile_contents, infile_pkginfo, None, None) data = spi.Index(show_progress=True) logging.debug("Importing to the database.") importer = system_pkgmap.InstallContentsImporter() importer.ImportData(data, show_progress=True, include_prefixes=frozenset(["CSW"]))
def test_ParseSrv4PkgmapLineTypeSymlink(self): spi = system_pkgmap.Indexer() expected = { 'cksum': None, 'class': 'none', 'major': None, 'minor': None, 'group': None, 'mode': None, 'modtime': None, 'owner': None, 'path': '/opt/csw/apache2/lib/libapr-1.so.0', 'pkgnames': ['CSWapache2rt'], 'size': None, 'target': 'libapr-1.so.0.3.8', 'type': 's', 'line': PKGMAP_LINE_3, } self.assertEqual(expected, spi._ParseSrv4PkgmapLine(PKGMAP_LINE_3))
def test_ParseSrv4PkgmapLineFile(self): spi = system_pkgmap.Indexer() expected = { 'cksum': '28258', 'class': 'none', 'group': 'bin', 'major': None, 'minor': None, 'mode': '0755', 'modtime': '1018129099', 'owner': 'root', 'path': '/usr/lib/sparcv9/libpthread.so.1', 'pkgnames': ['SUNWcslx'], 'size': '41296', 'target': None, 'type': 'f', 'line': PKGMAP_LINE_1 } self.assertEqual(expected, spi._ParseSrv4PkgmapLine(PKGMAP_LINE_1))
def test_ParseSrv4PkgmapLineTypeQuestionMark(self): """A question mark is not a valid type, but we have to cope with it.""" spi = system_pkgmap.Indexer() expected = { 'modtime': None, 'major': None, 'pkgnames': ['CSWgcc3g77', 'CSWgcc3core'], 'cksum': None, 'owner': None, 'path': '/opt/csw/gcc3/lib/gcc/sparc-sun-solaris2.8/3.4.6/include', 'line': PKGMAP_LINE_5, 'class': 'none', 'size': None, 'group': None, 'target': None, 'mode': None, 'type': 'd', 'minor': None, } self.assertEqual(expected, spi._ParseSrv4PkgmapLine(PKGMAP_LINE_5))
def test_ParseSrv4PkgmapLineTypePipe(self): """A pipe is a valid type and we have to cope with it.""" spi = system_pkgmap.Indexer() expected = { 'modtime': None, 'major': None, 'pkgnames': ['SUNWscn-agentfacade-r'], 'cksum': None, 'owner': 'root', 'path': '/etc/scn/scn_aa_read', 'line': PKGMAP_LINE_8, 'class': 'none', 'size': None, 'group': 'sys', 'target': None, 'mode': '0600', 'type': 'p', 'minor': None, } self.assertEqual(expected, spi._ParseSrv4PkgmapLine(PKGMAP_LINE_8))
def test_ParseSrv4PkgmapLibc(self): """A question mark is not a valid type, but we have to cope with it.""" spi = system_pkgmap.Indexer() expected = { 'modtime': '1250803966', 'major': None, 'pkgnames': ['SUNWcsl'], 'cksum': '58567', 'owner': 'root', 'path': '/usr/lib/libc.so.1', 'line': '/usr/lib/libc.so.1 f none 0755 root bin 867444 58567 1250803966 SUNWcsl', 'class': 'none', 'size': '867444', 'group': 'bin', 'target': None, 'mode': '0755', 'type': 'f', 'minor': None, } self.assertEqual(expected, spi._ParseSrv4PkgmapLine(PKGMAP_LINE_6))
def test_ParseIpsPkgListLine(self): spi = system_pkgmap.Indexer() expected = ('SUNWdeveloper-versioning-sccs', 'Source Code Control System') self.assertEqual(expected, spi._ParseIpsPkgListLine(PKGLIST_LINE_1))
def test_ParseSrv4PkginfoLine(self): spi = system_pkgmap.Indexer() expected = ('SUNWwpau', 'Wireless WPA Supplicant, (Usr)') self.assertEqual(expected, spi._ParseSrv4PkginfoLine(PKGINFO_LINE_1))
def test_GetDataStructure(self): spi = system_pkgmap.Indexer() expected = { 'arch': 'sparc', 'osrel': 'SunOS5.11', 'contents': [{ 'cksum': '28258', 'class': 'none', 'group': 'bin', 'line': '/usr/lib/sparcv9/libpthread.so.1 f none 0755 root bin 41296 28258 1018129099 SUNWcslx', 'major': None, 'minor': None, 'mode': '0755', 'modtime': '1018129099', 'owner': 'root', 'path': '/usr/lib/sparcv9/libpthread.so.1', 'pkgnames': ['SUNWcslx'], 'size': '41296', 'target': None, 'type': 'f' }, { 'cksum': '6287', 'class': 'none', 'group': 'bin', 'line': '/usr/lib/libCrun.so.1 f none 0755 root bin 63588 6287 1256043984 SUNWlibC', 'major': None, 'minor': None, 'mode': '0755', 'modtime': '1256043984', 'owner': 'root', 'path': '/usr/lib/libCrun.so.1', 'pkgnames': ['SUNWlibC'], 'size': '63588', 'target': None, 'type': 'f' }, { 'group': None, 'line': 'bin\tlink\tsystem/core-os\t./usr/bin', 'mode': None, 'owner': None, 'path': '/bin', 'pkgnames': ['SUNWsystem-core-os'], 'target': './usr/bin', 'type': 's' }, { 'group': 'sys', 'line': 'dev\tdir\tsystem/core-os\t\t0755\troot\tsys', 'mode': '0755', 'owner': 'root', 'path': '/dev', 'pkgnames': ['SUNWsystem-core-os'], 'target': None, 'type': 'd' }], 'pkginfo': { 'SUNWdeveloper-solarisstudio-122-c': u'C++ Compilers', 'SUNWdeveloper-versioning-sccs': u'Source Code Control System', 'SUNWpcan': u'Cisco-Aironet 802.11b driver', 'SUNWwpau': u'Wireless WPA Supplicant, (Usr)' } } srv4_pkginfos_stream = ( PKGINFO_LINE_1, PKGINFO_LINE_2, ) ips_pkginfos_stream = ( PKGLIST_LINE_1, PKGLIST_LINE_2, ) srv4_pkgcontents_stream = ( PKGMAP_LINE_1, PKGMAP_LINE_2, ) ips_pkgcontents_stream = ( PKGCONTENT_LINE_1, PKGCONTENT_LINE_2, ) self.assertEqual( expected, spi.GetDataStructure(srv4_pkgcontents_stream, srv4_pkginfos_stream, ips_pkgcontents_stream, ips_pkginfos_stream, 'SunOS5.11', 'sparc', False))
def test_IpsNameToSrv4Name(self): spi = system_pkgmap.Indexer() self.assertEquals('SUNWsystem-core-os', spi._IpsNameToSrv4Name("system/core-os"))
def test_ParseSrv4PkgmapLineTypeWrongSyntax(self): spi = system_pkgmap.Indexer() self.assertRaises(system_pkgmap.ParsingError, spi._ParseSrv4PkgmapLine, "/")
def test_ParseSrv4PkgmapExclamationMark(self): spi = system_pkgmap.Indexer() self.assertEqual(["!CSWmozilla"], spi._ParseSrv4PkgmapLine(PKGMAP_LINE_7)["pkgnames"])
outfile = None infile_contents = common_constants.DEFAULT_INSTALL_CONTENTS_FILE infile_pkginfo = None osrel, arch = (None, None) if len(args) >= 2: infile_contents = args[0] infile_pkginfo = args[1] if len(args) >= 3: outfile = args[2] if len(args) >= 4: if len(args) == 5: osrel, arch = args[3:5] else: raise UsageError("Wrong number of arguments (%s), see usage." % len(args)) spi = system_pkgmap.Indexer(outfile, infile_contents, infile_pkginfo, osrel, arch) spi.IndexAndSave() elif command == 'import-system-file': infile = args[0] importer = system_pkgmap.InstallContentsImporter() infile_fd = open(infile, "r") importer.ImportFromFile(infile_fd, show_progress=True) elif (command, subcommand) == ('pkg', 'search'): logging.debug("Searching for %s", args) sqo_osrel = m.OsRelease.selectBy(short_name=options.osrel).getOne() sqo_arch = m.Architecture.selectBy(name=options.arch).getOne() sqo_catrel = m.CatalogRelease.selectBy(name=options.catrel).getOne() if len(args) < 1: logging.fatal("Wrong number of arguments: %s", len(args)) raise SystemExit for catalogname in args:
def test_ParseInstallContents(self): spi = system_pkgmap.Indexer() data = (PKGMAP_LINE_1, PKGMAP_LINE_2, PKGMAP_LINE_3, PKGMAP_LINE_4) self.assertEqual(4, len(spi._ParseInstallContents(data, False)))