Esempio n. 1
0
    def test_find_package_desktopfile(self):
        '''find_package_desktopfile().'''

        # package without any .desktop file
        nodesktop = 'bash'
        assert len([f for f in packaging.get_files(nodesktop)
            if f.endswith('.desktop')]) == 0

        # find a package with one and a package with multiple .desktop files
        onedesktop = None
        multidesktop = None
        for d in os.listdir('/usr/share/applications/'):
            if not d.endswith('.desktop'):
                continue
            pkg = packaging.get_file_package(
                os.path.join('/usr/share/applications/', d))
            num = len([f for f in packaging.get_files(pkg)
                if f.endswith('.desktop')])
            if not onedesktop and num == 1:
                onedesktop = pkg
            elif not multidesktop and num > 1:
                multidesktop = pkg

            if onedesktop and multidesktop:
                break

        if nodesktop:
            self.assertEqual(find_package_desktopfile(nodesktop), None, 'no-desktop package %s' % nodesktop)
        if multidesktop:
            self.assertEqual(find_package_desktopfile(multidesktop), None, 'multi-desktop package %s' % multidesktop)
        if onedesktop:
            d = find_package_desktopfile(onedesktop)
            self.assertNotEqual(d, None, 'one-desktop package %s' % onedesktop)
            self.assert_(os.path.exists(d))
            self.assert_(d.endswith('.desktop'))
Esempio n. 2
0
def find_file_package(file):
    '''Return the package that ships the given file.
    
    Return None if no package ships it.
    '''
    # resolve symlinks in directories
    (dir, name) = os.path.split(file)
    resolved_dir = os.path.realpath(dir)
    if os.path.isdir(resolved_dir):
        file = os.path.join(resolved_dir, name)

    if not likely_packaged(file):
        return None

    return packaging.get_file_package(file)
Esempio n. 3
0
def find_file_package(file):
    '''Return the package that ships the given file.
    
    Return None if no package ships it.
    '''
    # resolve symlinks in directories
    (dir, name) = os.path.split(file)
    resolved_dir = os.path.realpath(dir)
    if os.path.isdir(resolved_dir):
        file = os.path.join(resolved_dir, name)

    if not likely_packaged(file):
        return None

    return packaging.get_file_package(file)
Esempio n. 4
0
    def test_find_package_desktopfile(self):
        '''find_package_desktopfile().'''

        # package without any .desktop file
        nodesktop = 'bash'
        assert len([
            f for f in packaging.get_files(nodesktop) if f.endswith('.desktop')
        ]) == 0

        # find a package with one and a package with multiple .desktop files
        onedesktop = None
        multidesktop = None
        for d in os.listdir('/usr/share/applications/'):
            if not d.endswith('.desktop'):
                continue
            pkg = packaging.get_file_package(
                os.path.join('/usr/share/applications/', d))
            num = len([
                f for f in packaging.get_files(pkg) if f.endswith('.desktop')
            ])
            if not onedesktop and num == 1:
                onedesktop = pkg
            elif not multidesktop and num > 1:
                multidesktop = pkg

            if onedesktop and multidesktop:
                break

        if nodesktop:
            self.assertEqual(find_package_desktopfile(nodesktop), None,
                             'no-desktop package %s' % nodesktop)
        if multidesktop:
            self.assertEqual(find_package_desktopfile(multidesktop), None,
                             'multi-desktop package %s' % multidesktop)
        if onedesktop:
            d = find_package_desktopfile(onedesktop)
            self.assertNotEqual(d, None, 'one-desktop package %s' % onedesktop)
            self.assert_(os.path.exists(d))
            self.assert_(d.endswith('.desktop'))