summaryrefslogtreecommitdiff
path: root/portato/backend/catapult/package.py
blob: 2e4f471961e8cbdde4a1099232bcca9b008a2213 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# -*- coding: utf-8 -*-
#
# File: portato/backend/catapult/package.py
# This file is part of the Portato-Project, a graphical portage-frontend.
#
# Copyright (C) 2007-2008 René 'Necoro' Neumann
# This is free software.  You may redistribute copies of it under the terms of
# the GNU General Public License version 2.
# There is NO WARRANTY, to the extent permitted by law.
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>

from __future__ import absolute_import, with_statement

from ..package import Package
from .. import flags
from .. import system
from ..exceptions import BlockedException, PackageNotFoundException
from ...helper import debug, unique_array

import dbus
import catapult

import os.path

class CatapultPackage(Package):

	bus = dbus.SessionBus()
	dbus_object = bus.get_object(catapult.get_dbus_address(catapult.DEFAULT), catapult.CATAPULT_PACKAGE_BUS, follow_name_owner_changes = True)
	proxy = dbus.Interface(dbus_object, catapult.CATAPULT_PACKAGE_IFACE)

	_expand = {}
	
	def _new_flags (self):
		flags = self.get_new_use_flags()

		nflags = []

		for flag in flags:
			if flag[0] == "~":
				nflags.append((flag[1:], True))
			else:
				nflags.append((flag, False))

		return nflags
	
	def use_expanded (self, flag, suggest = None):
		
		exp = self._expand.get(flag, False)

		if exp is False:
			if not suggest:
				suggest = ""
			s = str(self.proxy.use_expanded(self.get_cpv(), flag, suggest))
			if not s:
				s = None

			self._expand[flag] = s
			return s
		else:
			return exp

	def get_package_path(self):
		return str(self.proxy.get_package_path(self.get_cpv()))

	def is_installed(self):
		return self.proxy.is_installed(self.get_cpv())

	def is_overlay(self):
		return self.proxy.is_in_overlay(self.get_cpv())

	def get_overlay_path(self):
		return str(self.proxy.get_overlay_path(self.get_cpv()))
		
	def is_in_system (self):
		return self.proxy.is_in_system(self.get_cpv())

	def is_missing_keyword(self):
		return self.proxy.is_missing_keyword(self.get_cpv())
		
	def is_testing(self, use_keywords = False):
		if not use_keywords:
			return self.proxy.is_testing(self.get_cpv(), False)
		else:
			status = flags.new_testing_status(self.get_cpv())
			if status is None:
				return self.proxy.is_testing(self.get_cpv(), True)
			else:
				return status

	def is_masked (self, use_changed = True):
		if use_changed:
			status = flags.new_masking_status(self.get_cpv())
			if status != None: # we have locally changed it
				if status == "masked": return True
				elif status == "unmasked": return False
				else:
					error(_("BUG in flags.new_masking_status. It returns \'%s\'"), status)
			else: # we have not touched the status
				return self.proxy.is_masked(self.get_cpv())
		else: # we want the original portage value XXX: bug if masked by user AND by system
			if self.proxy.is_masked(self.get_cpv()):
				if not flags.is_locally_masked(self, changes = False): # assume that if it is locally masked, it is not masked by the system
					return True

			return False

	def get_masking_reason (self):
		return str(self.proxy.get_masking_reason(self.get_cpv()))
		
	def get_iuse_flags (self, installed = False, removeForced = True):
		return [str(x) for x in self.proxy.get_iuse_flags(self.get_cpv(), installed, removeForced)]

	def get_matched_dep_packages (self, depvar):
		return [str(x) for x in self.proxy.get_matched_dep_packages(self.get_cpv(), self._new_flags())]
		
	def get_dep_packages (self, depvar = ["RDEPEND", "PDEPEND", "DEPEND"], with_criterions = False):
		pkgs = self.proxy.get_dep_packages(self.get_cpv(), depvar, self._new_flags())

		if not with_criterions:
			return [str(x) for x,y in pkgs]
		else:
			return [(str(x),str(y)) for x,y in pkgs]

	def get_global_settings(self, key, installed = True):
		return str(self.proxy.get_global_settings(self.get_cpv(), key, installed))

	def get_ebuild_path(self):
		return str(self.proxy.get_ebuild_path(self.get_cpv()))

	def get_package_settings(self, var, tree = True):
		return str(self.proxy.get_package_settings(self.get_cpv(), var, tree))

	def get_installed_use_flags(self):
		return self.proxy.get_installed_use_flags(self.get_cpv())

	def get_actual_use_flags(self):
		return self.proxy.get_actual_use_flags(self.get_cpv(), self._new_flags())

	def compare_version(self, other):
		return self.proxy.compare_version(self.get_cpv(), other.get_cpv())

	def matches (self, criterion):
		return self.proxy.matches(self.get_cpv(), criterion)

	def get_files (self):
		return self.proxy.get_files(self.get_cpv())

	def get_name(self):
		return str(self.proxy.get_name(self.get_cpv()))

	def get_version(self):
		return str(self.proxy.get_version(self.get_cpv()))

	def get_category(self):
		return str(self.proxy.get_category(self.get_cpv()))