Exemplo n.º 1
0
        def packages_newer_than(self, unix_time):
            """
			Returns list of packages which were modified between unix_time and present
			Requires root permissions.
			"""

            if not os.access('/var/log/emerge.log', os.R_OK):
                raise DatabasePermissions

            newer = PackagesCollection()
            process = subprocess.Popen(['qlop', '-lC'], stdout=subprocess.PIPE)
            packages = process.communicate()[0]
            for package in packages.decode().split('\n')[:-1]:
                package = package.split(" >>> ")

                # There actually should be %e instead of %d
                modified = time.mktime(
                    time.strptime(package[0], "%a %b %d %H:%M:%S %Y"))
                if modified >= unix_time:
                    pkg_name = package[
                        1]  # Package name with version, let's cut it off
                    pkg_name = self._pkg_name_without_version(pkg_name)
                    newer.append(Package(pkg_name, modified))

            return newer
Exemplo n.º 2
0
        def packages_newer_than(self, unix_time):
            """
			Returns list of packages which were modified between unix_time and present
			"""
            new_pkgs = PackagesCollection()
            for pkg in self.db.pkgcache:
                if pkg.installdate > unix_time:
                    new_pkgs.append(Package(pkg.name, pkg.installdate))

            return new_pkgs
Exemplo n.º 3
0
		def packages_newer_than(self, unix_time):
			"""
			Returns list of packages which were modified between unix_time and present
			"""
			new_pkgs = PackagesCollection()
			for pkg in self.db.pkgcache:
				if pkg.installdate > unix_time:
					new_pkgs.append(Package(pkg.name, pkg.installdate))

			return new_pkgs
Exemplo n.º 4
0
Arquivo: rpm.py Projeto: jturel/tracer
        def packages_newer_than(self, unix_time):
            """
			Returns list of packages which were modified between unix_time and present
			Requires root permissions.
			"""

            # Package manager wasn't used yet
            if not os.path.exists(self.history_path):
                return PackagesCollection([])

            if self.opts.get('modern_swdb'):
                sql = """
					SELECT DISTINCT rpm.name, trans.dt_end AS end

					FROM trans JOIN trans_item JOIN rpm
					ON trans.id=trans_item.trans_id
					AND trans_item.item_id=rpm.item_id

					WHERE trans.dt_begin > ?
					ORDER BY rpm.name
				"""
            else:
                sql = """
					SELECT DISTINCT pkgtups.name, trans_end.timestamp AS end

					FROM trans_beg JOIN trans_end JOIN trans_data_pkgs JOIN pkgtups
					ON trans_beg.tid=trans_end.tid
					AND trans_data_pkgs.tid=trans_beg.tid
					AND trans_data_pkgs.pkgtupid=pkgtups.pkgtupid

					WHERE trans_beg.timestamp > ?
					ORDER BY pkgtups.name
				"""

            try:
                packages = PackagesCollection()
                sqlite = self._database_file()
                conn = sqlite3.connect(sqlite)
                conn.row_factory = sqlite3.Row
                cursor = conn.cursor()
                cursor.execute(sql, [unix_time])

                for result in cursor.fetchall():
                    packages.append(Package(result['name'], result['end']))

                return packages

            except sqlite3.OperationalError as e:
                raise LockedDatabase() if str(
                    e) == 'database is locked' else DatabasePermissions()
Exemplo n.º 5
0
		def packages_newer_than(self, unix_time):
			"""
			Returns list of packages which were modified between unix_time and present
			Requires root permissions.
			"""

			# Package manager wasn't used yet
			if not os.path.exists(self.history_path):
				return PackagesCollection([])

			if self.opts.get('modern_swdb'):
				sql = """
					SELECT DISTINCT rpm.name, trans.dt_end AS end

					FROM trans JOIN trans_item JOIN rpm
					ON trans.id=trans_item.trans_id
					AND trans_item.item_id=rpm.item_id

					WHERE trans.dt_begin > ?
					ORDER BY rpm.name
				"""
			else:
				sql = """
					SELECT DISTINCT pkgtups.name, trans_end.timestamp AS end

					FROM trans_beg JOIN trans_end JOIN trans_data_pkgs JOIN pkgtups
					ON trans_beg.tid=trans_end.tid
					AND trans_data_pkgs.tid=trans_beg.tid
					AND trans_data_pkgs.pkgtupid=pkgtups.pkgtupid

					WHERE trans_beg.timestamp > ?
					ORDER BY pkgtups.name
				"""

			try:
				packages = PackagesCollection()
				sqlite = self._database_file()
				conn = sqlite3.connect(sqlite)
				conn.row_factory = sqlite3.Row
				cursor = conn.cursor()
				cursor.execute(sql, [unix_time])

				for result in cursor.fetchall():
					packages.append(Package(result['name'], result['end']))

				return packages

			except sqlite3.OperationalError as e:
				raise LockedDatabase() if str(e) == 'database is locked' else DatabasePermissions()
Exemplo n.º 6
0
    def _modified_packages(self):
        """Returns list of packages what tracer should care about"""
        if self.specified_packages and self.now:
            return PackagesCollection(self.specified_packages)

        timestamp = self.timestamp if self.timestamp else System.boot_time()
        packages = self._PACKAGE_MANAGER.packages_newer_than(timestamp)
        packages = packages.intersection(self.specified_packages)
        return packages
Exemplo n.º 7
0
	def packages_newer_than(self, unix_time):
		"""
		Returns list of packages which were modified between unix_time and present
		Packages in list should be dictionaries with keys {"name", "modified"}
		"""
		# @FIXME move import to top-level
		from tracer.resources.collections import PackagesCollection
		packages_lists = [p.packages_newer_than(unix_time) for p in self.package_managers]
		return PackagesCollection(itertools.chain.from_iterable(packages_lists))
Exemplo n.º 8
0
        def packages_newer_than(self, unix_time):
            """
			Returns list of packages which were modified between unix_time and present
			Requires root permissions.
			"""
            newer = PackagesCollection()
            log = open(self.dpkg_log, 'r')
            for line in log:
                line = line.split(" ")

                if line[2] != "upgrade":
                    continue

                # There actually should be %e instead of %d
                modified = time.mktime(
                    time.strptime(line[0] + " " + line[1],
                                  "%Y-%m-%d %H:%M:%S"))

                if modified >= unix_time:
                    pkg_name = line[3].split(":")[0]
                    newer.append(Package(pkg_name, modified))
            return newer
Exemplo n.º 9
0
		def packages_newer_than(self, unix_time):
			"""
			Returns list of packages which were modified between unix_time and present
			Requires root permissions.
			"""
			newer = PackagesCollection()
			log = open(self.dpkg_log, 'r')
			for line in log:
				line = line.split(" ")

				if line[2] != "upgrade":
					continue

				# There actually should be %e instead of %d
				modified = time.mktime(
					time.strptime(line[0] + " " + line[1],
					"%Y-%m-%d %H:%M:%S"))

				if modified >= unix_time:
					pkg_name = line[3].split(":")[0]
					newer.append(Package(pkg_name, modified))
			return newer
Exemplo n.º 10
0
		def packages_newer_than(self, unix_time):
			"""
			Returns list of packages which were modified between unix_time and present
			Requires root permissions.
			"""

			if not os.access('/var/log/emerge.log', os.R_OK):
				raise DatabasePermissions

			newer = PackagesCollection()
			process = subprocess.Popen(['qlop', '-lC'], stdout=subprocess.PIPE)
			packages = process.communicate()[0]
			for package in packages.decode().split('\n')[:-1]:
				package = package.split(" >>> ")

				# There actually should be %e instead of %d
				modified = time.mktime(time.strptime(package[0], "%a %b %d %H:%M:%S %Y"))
				if modified >= unix_time:
					pkg_name = package[1] # Package name with version, let's cut it off
					pkg_name = self._pkg_name_without_version(pkg_name)
					newer.append(Package(pkg_name, modified))

			return newer
Exemplo n.º 11
0
	def test_packages_intersection(self):
		p1 = Package("foo")
		p2 = Package("bar")
		p3 = Package("baz")
		p4 = Package("qux", 123)
		p5 = Package("qux")
		c1 = PackagesCollection([p1, p2, p3, p4])
		self.assertEqual(c1.intersection([p1, p3]).sorted("name"), PackagesCollection([p1, p3]).sorted("name"))
		self.assertEqual(c1.intersection(None), c1)
		self.assertIsNotNone(c1.intersection([p5])[0].modified)
Exemplo n.º 12
0
 def packages_newer_than(self, unix_time):
     return PackagesCollection(
         filter(lambda p: p.modified >= unix_time, self._packages))