示例#1
0
def get_use_flag_dict(portdir):
    """ Get all the use flags and return them as a dictionary 
        key = use flag forced to lowercase
        data = list[0] = 'local' or 'global'
               list[1] = 'package-name'
               list[2] = description of flag   
    """
    dict = {}

    # process standard use flags

    List = portage.grabfile(portdir + '/profiles/use.desc')
    for item in List:
        index = item.find(' - ')
        dict[item[:index].strip().lower()] = ['global', '', item[index+3:]]

    # process local (package specific) use flags

    List = portage.grabfile(portdir + '/profiles/use.local.desc')
    for item in List:
        index = item.find(' - ')
        data = item[:index].lower().split(':')
        try: # got an error starting porthole==> added code to catch it, but it works again???
            dict[data[1].strip()] = ['local', data[0].strip(), item[index+3:]]
        except:
            debug.dprint("PORTAGELIB: get_use_flag_dict(); error in index??? data[0].strip, item[index:]")
            debug.dprint(data[0].strip())
            debug.dprint(item[index:])
    return dict
示例#2
0
	def get_profile(self):
		"""
		Return selected portage profile
		"""
		profilever = None
		profile = portage.settings.profile_path
		if profile:
			profilever = relative_profile_path(self.portdir, profile)
			if profilever is None:
				try:
					for parent in portage.grabfile(
							os.path.join(profile, 'parent')
					):
						profilever = relative_profile_path(
								self.portdir, os.path.join(profile, parent)
						)

						if profilever is not None:
							break
				except portage.exception.PortageException:
					pass

				if profilever is None:
					try:
						profilever = '!' + os.readlink(profile)
					except (OSError):
						pass

		if profilever is None:
			profilever = 'Unknown'

		return profilever
示例#3
0
def _global_use_description():
    out = {}
    for line in portage.grabfile('/usr/portage/profiles/use.desc'):
        flag, desc = line.split(" - ", 1)
        out[flag] = desc

    return out
示例#4
0
    def isInjected(self):
        """
		Looks if the GLSA ID is in the GLSA checkfile to check if this
		GLSA should be marked as applied.

		@rtype:		Boolean
		@returns:	True if the GLSA is in the inject file, False if not
		"""
        if not os.access(self.config["CHECKFILE"], os.R_OK):
            return False
        aList = portage.grabfile(self.config["CHECKFILE"])
        return (self.nr in aList)
示例#5
0
	def retrieve_head(self, **kwargs):
		'''Get information about the head commit'''
		if kwargs:
			self._kwargs(kwargs)
		last_sync = portage.grabfile(os.path.join(self.repo.location, "metadata", "timestamp.commit"))
		ret = (1, False)
		if last_sync:
			try:
				ret = (os.EX_OK, last_sync[0].split()[0])
			except IndexError:
				pass
		return ret
示例#6
0
 def getLastSync(self):
     """
     Return portage tree last sync time
     """
     lastsync = None
     try:
         lastsync = portage.grabfile(os.path.join(self.portdir, "metadata", "timestamp.chk"))
     except portage.exception.PortageException:
         pass
     if lastsync is None:
         return "Unknown"
     return lastsync[0]
示例#7
0
文件: rsync.py 项目: gentoo/portage
	def retrieve_head(self, **kwargs):
		'''Get information about the head commit'''
		if kwargs:
			self._kwargs(kwargs)
		last_sync = portage.grabfile(os.path.join(self.repo.location, "metadata", "timestamp.commit"))
		ret = (1, False)
		if last_sync:
			try:
				ret = (os.EX_OK, last_sync[0].split()[0])
			except IndexError:
				pass
		return ret
示例#8
0
	def isInjected(self):
		"""
		Looks if the GLSA ID is in the GLSA checkfile to check if this
		GLSA should be marked as applied.

		@rtype:		Boolean
		@returns:	True if the GLSA is in the inject file, False if not
		"""
		if not os.access(self.config["CHECKFILE"], os.R_OK):
			return False
		aList = portage.grabfile(self.config["CHECKFILE"])
		return (self.nr in aList)
示例#9
0
	def get_last_sync(self):
		"""
		Return portage tree last sync time
		"""
		last_sync = None

		try:
			last_sync = portage.grabfile(
				os.path.join(self.portdir, 'metadata', 'timestamp.chk')
			)
		except portage.exception.PortageException:
			pass

		if last_sync is None:
			return 'Unknown'

		return last_sync[0]
示例#10
0
 def _expanded_use_flags(self):
     use_flags = []
     expand_desc_dir = os.path.join(main_tree_dir(), 'profiles', 'desc')
     try:
         expand_list = os.listdir(expand_desc_dir)
     except OSError:
         pass
     else:
         for desc_filename in expand_list:
             if not desc_filename.endswith('.desc'):
                 continue
             use_prefix = desc_filename[:-5].lower() + '_'
             for line in portage.grabfile(
                     os.path.join(expand_desc_dir, desc_filename)):
                 x = line.split()
                 if x:
                     use_flags.append(use_prefix + x[0])
     return set(use_flags)
示例#11
0
 def _expanded_use_flags(self):
     use_flags = []
     expand_desc_dir = os.path.join(main_tree_dir(), 'profiles', 'desc')
     try:
         expand_list = os.listdir(expand_desc_dir)
     except OSError:
         pass
     else:
         for desc_filename in expand_list:
             if not desc_filename.endswith('.desc'):
                 continue
             use_prefix = desc_filename[:-5].lower() + '_'
             for line in portage.grabfile(os.path.join(
                     expand_desc_dir, desc_filename)):
                 x = line.split()
                 if x:
                     use_flags.append(use_prefix + x[0])
     return set(use_flags)
示例#12
0
    def _do_rsync(self, syncuri, timestamp, opts):
        updatecache_flg = False
        is_synced = False
        if timestamp != 0 and "--quiet" not in opts:
            print(">>> Checking server timestamp ...")

        rsynccommand = [self.bin_command
                        ] + self.rsync_opts + self.extra_rsync_opts

        if self.proto == 'ssh' and self.ssh_opts:
            rsynccommand.append("--rsh=ssh " + self.ssh_opts)

        if "--debug" in opts:
            print(rsynccommand)

        local_state_unchanged = False
        exitcode = os.EX_OK
        servertimestamp = 0
        # Even if there's no timestamp available locally, fetch the
        # timestamp anyway as an initial probe to verify that the server is
        # responsive.  This protects us from hanging indefinitely on a
        # connection attempt to an unresponsive server which rsync's
        # --timeout option does not prevent.

        #if True:
        # Temporary file for remote server timestamp comparison.
        # NOTE: If FEATURES=usersync is enabled then the tempfile
        # needs to be in a directory that's readable by the usersync
        # user. We assume that ${PORTAGE_TMPDIR}/portage will satisfy this
        # requirement, since that's not necessarily true for the
        # default directory used by the tempfile module.
        if self.usersync_uid is not None:
            tmpdir = os.path.join(self.settings['PORTAGE_TMPDIR'], 'portage')
            ensure_dirs_kwargs = {}
            if portage.secpass >= 1:
                ensure_dirs_kwargs['gid'] = portage.portage_gid
                ensure_dirs_kwargs['mode'] = 0o70
                ensure_dirs_kwargs['mask'] = 0
            portage.util.ensure_dirs(tmpdir, **ensure_dirs_kwargs)
        else:
            # use default dir from tempfile module
            tmpdir = None
        fd, tmpservertimestampfile = \
         tempfile.mkstemp(dir=tmpdir)
        os.close(fd)
        if self.usersync_uid is not None:
            portage.util.apply_permissions(tmpservertimestampfile,
                                           uid=self.usersync_uid)
        command = rsynccommand[:]
        command.append('--inplace')
        command.append(syncuri.rstrip("/") + \
         "/metadata/timestamp.chk")
        command.append(tmpservertimestampfile)
        content = None
        pids = []
        try:
            # Timeout here in case the server is unresponsive.  The
            # --timeout rsync option doesn't apply to the initial
            # connection attempt.
            try:
                if self.rsync_initial_timeout:
                    portage.exception.AlarmSignal.register(
                        self.rsync_initial_timeout)

                pids.extend(
                    portage.process.spawn(command,
                                          returnpid=True,
                                          **self.spawn_kwargs))
                exitcode = os.waitpid(pids[0], 0)[1]
                if self.usersync_uid is not None:
                    portage.util.apply_permissions(tmpservertimestampfile,
                                                   uid=os.getuid())
                content = portage.grabfile(tmpservertimestampfile)
            finally:
                if self.rsync_initial_timeout:
                    portage.exception.AlarmSignal.unregister()
                try:
                    os.unlink(tmpservertimestampfile)
                except OSError:
                    pass
        except portage.exception.AlarmSignal:
            # timed out
            print('timed out')
            # With waitpid and WNOHANG, only check the
            # first element of the tuple since the second
            # element may vary (bug #337465).
            if pids and os.waitpid(pids[0], os.WNOHANG)[0] == 0:
                os.kill(pids[0], signal.SIGTERM)
                os.waitpid(pids[0], 0)
            # This is the same code rsync uses for timeout.
            exitcode = 30
        else:
            if exitcode != os.EX_OK:
                if exitcode & 0xff:
                    exitcode = (exitcode & 0xff) << 8
                else:
                    exitcode = exitcode >> 8

        if content:
            try:
                servertimestamp = time.mktime(
                    time.strptime(content[0], TIMESTAMP_FORMAT))
            except (OverflowError, ValueError):
                pass
        del command, pids, content

        if exitcode == os.EX_OK:
            if (servertimestamp != 0) and (servertimestamp == timestamp):
                local_state_unchanged = True
                is_synced = True
                self.logger(self.xterm_titles,
                            ">>> Cancelling sync -- Already current.")
                print()
                print(">>>")
                print(
                    ">>> Timestamps on the server and in the local repository are the same."
                )
                print(
                    ">>> Cancelling all further sync action. You are already up to date."
                )
                print(">>>")
                print(">>> In order to force sync, remove '%s'." %
                      self.servertimestampfile)
                print(">>>")
                print()
            elif (servertimestamp != 0) and (servertimestamp < timestamp):
                self.logger(self.xterm_titles,
                            ">>> Server out of date: %s" % syncuri)
                print()
                print(">>>")
                print(">>> SERVER OUT OF DATE: %s" % syncuri)
                print(">>>")
                print(">>> In order to force sync, remove '%s'." %
                      self.servertimestampfile)
                print(">>>")
                print()
                exitcode = SERVER_OUT_OF_DATE
            elif (servertimestamp == 0) or (servertimestamp > timestamp):
                # actual sync
                command = rsynccommand[:]

                submodule_paths = self._get_submodule_paths()
                if submodule_paths:
                    # The only way to select multiple directories to
                    # sync, without calling rsync multiple times, is
                    # to use --relative.
                    command.append("--relative")
                    for path in submodule_paths:
                        # /./ is special syntax supported with the
                        # rsync --relative option.
                        command.append(syncuri + "/./" + path)
                else:
                    command.append(syncuri + "/")

                command.append(self.download_dir)

                exitcode = None
                try:
                    exitcode = portage.process.spawn(command,
                                                     **self.spawn_kwargs)
                finally:
                    if exitcode is None:
                        # interrupted
                        exitcode = 128 + signal.SIGINT

                    #   0	Success
                    #   1	Syntax or usage error
                    #   2	Protocol incompatibility
                    #   5	Error starting client-server protocol
                    #  35	Timeout waiting for daemon connection
                    if exitcode not in (0, 1, 2, 5, 35):
                        # If the exit code is not among those listed above,
                        # then we may have a partial/inconsistent sync
                        # state, so our previously read timestamp as well
                        # as the corresponding file can no longer be
                        # trusted.
                        timestamp = 0
                        try:
                            os.unlink(self.servertimestampfile)
                        except OSError:
                            pass
                    else:
                        updatecache_flg = True

                if exitcode in [0, 1, 3, 4, 11, 14, 20, 21]:
                    is_synced = True
        elif exitcode in [1, 3, 4, 11, 14, 20, 21]:
            is_synced = True
        else:
            # Code 2 indicates protocol incompatibility, which is expected
            # for servers with protocol < 29 that don't support
            # --prune-empty-directories.  Retry for a server that supports
            # at least rsync protocol version 29 (>=rsync-2.6.4).
            pass

        return local_state_unchanged, is_synced, exitcode, updatecache_flg
示例#13
0
	def _do_rsync(self, syncuri, timestamp, opts):
		is_synced = False
		if timestamp != 0 and "--quiet" not in opts:
			print(">>> Checking server timestamp ...")

		rsynccommand = [self.bin_command] + self.rsync_opts + self.extra_rsync_opts

		if self.proto == 'ssh' and self.ssh_opts:
			rsynccommand.append("--rsh=ssh " + self.ssh_opts)

		if "--debug" in opts:
			print(rsynccommand)

		exitcode = os.EX_OK
		servertimestamp = 0
		# Even if there's no timestamp available locally, fetch the
		# timestamp anyway as an initial probe to verify that the server is
		# responsive.  This protects us from hanging indefinitely on a
		# connection attempt to an unresponsive server which rsync's
		# --timeout option does not prevent.

		#if True:
		# Temporary file for remote server timestamp comparison.
		# NOTE: If FEATURES=usersync is enabled then the tempfile
		# needs to be in a directory that's readable by the usersync
		# user. We assume that PORTAGE_TMPDIR will satisfy this
		# requirement, since that's not necessarily true for the
		# default directory used by the tempfile module.
		if self.usersync_uid is not None:
			tmpdir = self.settings['PORTAGE_TMPDIR']
		else:
			# use default dir from tempfile module
			tmpdir = None
		fd, tmpservertimestampfile = \
			tempfile.mkstemp(dir=tmpdir)
		os.close(fd)
		if self.usersync_uid is not None:
			portage.util.apply_permissions(tmpservertimestampfile,
				uid=self.usersync_uid)
		command = rsynccommand[:]
		command.append(syncuri.rstrip("/") + \
			"/metadata/timestamp.chk")
		command.append(tmpservertimestampfile)
		content = None
		pids = []
		try:
			# Timeout here in case the server is unresponsive.  The
			# --timeout rsync option doesn't apply to the initial
			# connection attempt.
			try:
				if self.rsync_initial_timeout:
					portage.exception.AlarmSignal.register(
						self.rsync_initial_timeout)

				pids.extend(portage.process.spawn(
					command, returnpid=True,
					**portage._native_kwargs(self.spawn_kwargs)))
				exitcode = os.waitpid(pids[0], 0)[1]
				if self.usersync_uid is not None:
					portage.util.apply_permissions(tmpservertimestampfile,
						uid=os.getuid())
				content = portage.grabfile(tmpservertimestampfile)
			finally:
				if self.rsync_initial_timeout:
					portage.exception.AlarmSignal.unregister()
				try:
					os.unlink(tmpservertimestampfile)
				except OSError:
					pass
		except portage.exception.AlarmSignal:
			# timed out
			print('timed out')
			# With waitpid and WNOHANG, only check the
			# first element of the tuple since the second
			# element may vary (bug #337465).
			if pids and os.waitpid(pids[0], os.WNOHANG)[0] == 0:
				os.kill(pids[0], signal.SIGTERM)
				os.waitpid(pids[0], 0)
			# This is the same code rsync uses for timeout.
			exitcode = 30
		else:
			if exitcode != os.EX_OK:
				if exitcode & 0xff:
					exitcode = (exitcode & 0xff) << 8
				else:
					exitcode = exitcode >> 8

		if content:
			try:
				servertimestamp = time.mktime(time.strptime(
					content[0], TIMESTAMP_FORMAT))
			except (OverflowError, ValueError):
				pass
		del command, pids, content

		if exitcode == os.EX_OK:
			if (servertimestamp != 0) and (servertimestamp == timestamp):
				self.logger(self.xterm_titles,
					">>> Cancelling sync -- Already current.")
				print()
				print(">>>")
				print(">>> Timestamps on the server and in the local repository are the same.")
				print(">>> Cancelling all further sync action. You are already up to date.")
				print(">>>")
				print(">>> In order to force sync, remove '%s'." % self.servertimestampfile)
				print(">>>")
				print()
				return is_synced, exitcode
			elif (servertimestamp != 0) and (servertimestamp < timestamp):
				self.logger(self.xterm_titles,
					">>> Server out of date: %s" % syncuri)
				print()
				print(">>>")
				print(">>> SERVER OUT OF DATE: %s" % syncuri)
				print(">>>")
				print(">>> In order to force sync, remove '%s'." % self.servertimestampfile)
				print(">>>")
				print()
				exitcode = SERVER_OUT_OF_DATE
			elif (servertimestamp == 0) or (servertimestamp > timestamp):
				# actual sync
				command = rsynccommand + [syncuri+"/", self.repo.location]
				exitcode = None
				try:
					exitcode = portage.process.spawn(command,
						**portage._native_kwargs(self.spawn_kwargs))
				finally:
					if exitcode is None:
						# interrupted
						exitcode = 128 + signal.SIGINT

					#   0	Success
					#   1	Syntax or usage error
					#   2	Protocol incompatibility
					#   5	Error starting client-server protocol
					#  35	Timeout waiting for daemon connection
					if exitcode not in (0, 1, 2, 5, 35):
						# If the exit code is not among those listed above,
						# then we may have a partial/inconsistent sync
						# state, so our previously read timestamp as well
						# as the corresponding file can no longer be
						# trusted.
						timestamp = 0
						try:
							os.unlink(self.servertimestampfile)
						except OSError:
							pass

				if exitcode in [0,1,3,4,11,14,20,21]:
					is_synced = True
		elif exitcode in [1,3,4,11,14,20,21]:
			is_synced = True
		else:
			# Code 2 indicates protocol incompatibility, which is expected
			# for servers with protocol < 29 that don't support
			# --prune-empty-directories.  Retry for a server that supports
			# at least rsync protocol version 29 (>=rsync-2.6.4).
			pass
		return is_synced, exitcode
示例#14
0
 def _auto_use_flags(self):
     return set(
         portage.grabfile(
             os.path.join(main_tree_dir(), 'profiles', 'arch.list')))
示例#15
0
 def _auto_use_flags(self):
     return set(portage.grabfile(os.path.join(main_tree_dir(), 'profiles',
         'arch.list')))
示例#16
0
preferred = []
allcp = vdb.cp_all()
for cp in allcp:
    preferred.append(Atom(cp))

preferred = prepare_prefdict(preferred)

tgraph = StateGraph()

allatoms = []
for atomstr in portage.settings.packages:
    if atomstr[0] == "*":
        allatoms.append(Atom(atomstr[1:]))

for atomstr in portage.grabfile("/var/lib/portage/world"):
    allatoms.append(Atom(atomstr))

rdeps = DependSpec(element_class=Atom)
rdeps.elements = allatoms
dummypkg = GluePkg("sets/world-1.0", "set", "0", [], DependSpec(), rdeps)
rdeps = transform_virtuals(dummypkg, rdeps, portage.settings.virtuals)
rdeps = transform_dependspec(rdeps, preferred)
rdeps.compact()
dummypkg = GluePkg("sets/world-1.0", "set", "0", [], DependSpec(), rdeps)
tgraph.add_package(dummypkg, True)


def create_pkg(cpv):
    aux = vdb.aux_get(cpv, ["SLOT", "USE", "RDEPEND", "PDEPEND"])
    slot = aux[0]