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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# -*- coding: utf-8 -*-
"""
package_manager.py
~~~~~~~~~~~~~~~~~~
This module implements some Python classes for the implementation of
the multiple package manager support.
:copyright: (c) 2010 by Rafael Goncalves Martins
:license: GPL-2, see LICENSE for more details.
"""
__all__ = [
'Portage',
'Pkgcore',
'Paludis',
]
import os
import subprocess
from g_octave.ebuild import Ebuild
class Base:
_client = ''
post_install = []
post_uninstall = []
check_overlay = lambda a,b,c: True
create_manifest = lambda a,b: os.EX_OK
def do_ebuilds(self, packages):
for package in packages:
Ebuild(package[len('g-octave/'):], pkg_manager=self).create()
class Portage(Base):
_client = 'emerge'
post_uninstall = [
'You may want to remove the dependencies too, using:',
'# emerge -av --depclean',
]
def __init__(self, ask=False, verbose=False, pretend=False, nocolor=False):
self._fullcommand = [self._client]
ask and self._fullcommand.append('--ask')
verbose and self._fullcommand.append('--verbose')
pretend and self._fullcommand.append('--pretend')
nocolor and self._fullcommand.append('--color=n')
def run_command(self, command):
return subprocess.call(self._fullcommand + command)
def install_package(self, pkgatom, catpkg):
return self.run_command([pkgatom])
def uninstall_package(self, pkgatom, catpkg):
return self.run_command(['--unmerge', pkgatom])
def update_package(self, pkgatom=None, catpkg=None):
if pkgatom is None:
pkgatom = self.installed_packages()
else:
pkgatom = [pkgatom]
self.do_ebuilds(pkgatom)
return self.run_command(['--update'] + pkgatom)
def installed_packages(self):
packages = []
with open('/var/lib/portage/world') as fp:
for line in fp:
if line.startswith('g-octave/'):
packages.append(line.strip())
return packages
def create_manifest(self, ebuild):
return subprocess.call(['ebuild', ebuild, 'manifest'])
def check_overlay(self, overlay, out):
import portage
if overlay not in portage.settings['PORTDIR_OVERLAY'].split(' '):
out.eerror('g-octave overlay is not configured!')
out.eerror('You must append your overlay dir to PORTDIR_OVERLAY.')
out.eerror('Overlay: %s' % overlay)
return False
return True
class Pkgcore(Base):
_client = 'pmerge'
post_uninstall = [
'You may want to remove the dependencies too, using:',
'# pmerge -av --clean',
]
def __init__(self, ask=False, verbose=False, pretend=False, nocolor=False):
self._fullcommand = [self._client]
ask and self._fullcommand.append('--ask')
verbose and self._fullcommand.append('--verbose')
pretend and self._fullcommand.append('--pretend')
nocolor and self._fullcommand.append('--nocolor')
def run_command(self, command):
return subprocess.call(self._fullcommand + command)
def install_package(self, pkgatom, catpkg):
return self.run_command([pkgatom])
def uninstall_package(self, pkgatom, catpkg):
return self.run_command(['--unmerge', pkgatom])
def update_package(self, pkgatom=None, catpkg=None):
if pkgatom is None:
pkgatom = self.installed_packages()
else:
pkgatom = [pkgatom]
self.do_ebuilds(pkgatom)
return self.run_command(['--upgrade', '--noreplace'] + pkgatom)
def installed_packages(self):
packages = []
p = subprocess.Popen([
'pquery',
'--vdb',
'--pkgset=world',
'--no-version',
'g-octave/*',
], stdout=subprocess.PIPE)
if p.wait() == os.EX_OK:
for line in p.stdout:
packages.append(line.strip())
return packages
class Paludis(Base):
_client = 'paludis'
post_uninstall = [
'You may want to remove the dependencies too, using:',
'# paludis --pretend --uninstall-unused',
]
def __init__(self, ask=False, verbose=False, pretend=False, nocolor=False):
self._fullcommand = [self._client]
# paludis doesn't supports '--ask'
if verbose:
self._fullcommand += [
'--show-reasons', 'full',
'--show-use-descriptions', 'all',
'--show-package-descriptions', 'all',
]
pretend and self._fullcommand.append('--pretend')
nocolor and self._fullcommand.append('--no-color')
def run_command(self, command):
return subprocess.call(self._fullcommand + command)
def install_package(self, pkgatom, catpkg):
return self.run_command([
'--install',
'--dl-upgrade', 'as-needed',
'--add-to-world-spec', catpkg,
pkgatom
])
def uninstall_package(self, pkgatom, catpkg):
return self.run_command(['--uninstall', pkgatom])
def update_package(self, pkgatom=None, catpkg=None):
if pkgatom is None:
pkgatom = self.installed_packages()
else:
pkgatom = [pkgatom]
self.do_ebuilds(pkgatom)
return self.run_command([
'--install',
'--dl-upgrade', 'as-needed',
'--dl-reinstall-targets', 'never',
] + pkgatom)
def installed_packages(self):
packages = []
p = subprocess.Popen([
'cave',
'print-ids',
'--matching', 'g-octave/*::installed',
'--format', '%c/%p\n',
], stdout=subprocess.PIPE)
if p.wait() == os.EX_OK:
for line in p.stdout:
packages.append(line.strip())
return packages
|