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
|
"""pomu command line interface"""
import click
from os import path
from pomu.patch.patch import process_changes
from pomu.repo.init import init_plain_repo, init_portage_repo
from pomu.repo.repo import portage_repo_path, portage_repos, pomu_active_repo
from pomu.source import dispatcher
from pomu.util.pkg import cpv_split
from pomu.util.result import ResultException
#TODO: global --repo option, (env var?)
class GlobalVars():
"""Global state"""
def __init__(self):
self.no_portage = False
self.repo_path = None
g_params = GlobalVars()
class needs_repo():
def __init__(self, func):
self.func = func
self.__name__ = func.__name__
def __call__(self, *args):
pomu_active_repo(g_params.no_portage, g_params.repo_path)
self.func(*args)
pass_globals = click.make_pass_decorator(GlobalVars, ensure=True)
@click.group()
@click.option('--no-portage', is_flag=True,
help='Do not setup the portage repo')
@click.option('--repo-path',
help='Path to the repo directory (used with --no-portage)')
def main(no_portage, repo_path):
"""A utility to manage portage overlays"""
g_params.no_portage = no_portage
g_params.repo_path = repo_path
@main.command()
@click.option('--list-repos', is_flag=True,
help='Lists available repositories')
@click.option('--create', is_flag=True,
help='Create the repository, instead of using an existing one')
@click.option('--repo-dir', envvar='POMU_REPO_DIR', default='/var/lib/pomu',
help='Path for creating new repos')
@click.argument('repo', required=False)
def init(g_params, list_repos, create, repo_dir, repo):
"""Initialise pomu for a repository"""
if list_repos:
print('Available repos:')
for prepo in portage_repos():
print('\t', prepo, portage_repo_path(prepo))
return
if g_params.no_portage:
print(init_plain_repo(create, g_params.repo_path).expect())
else:
print(init_portage_repo(create, repo, repo_dir).expect())
@main.command()
@needs_repo
def status():
"""Display pomu status"""
repo = pomu_active_repo()
if repo.name:
print('pomu is initialized for reporitory', repo.name, 'at', repo.root)
else:
print('pomu is initialized at', repo.root)
@main.command(name='import')
@click.argument('package', required=True)
@click.option('--patch', nargs = -1)
@needs_repo
def list(package, patch):
"""Imports a package"""
pkg = dispatcher.get_package(package).expect()
pkg.patch(patch)
res = pomu_active_repo().merge(pkg).expect()
print(res)
@main.command()
@click.argument('package', required=True)
@click.argument('patch', type=click.Path(exists=True), nargs=-1, required=True)
def patch(package):
"""Patch an existing package"""
category, name, *_ = cpv_split(package)
pkg = pomu_active_repo().get_package(name=name, category=category).expect()
pkg.patch(patch).expect()
@main.command()
@click.argument('--single', is_flag=True, required=False, default=False)
def commit(single):
repo = pomu_active_repo()
change_map = process_changes(repo).expect()
@main.command()
@click.option('--uri', is_flag=True,
help='Specify the package to remove by uri, instead of its name')
@click.argument('package', required=True)
@needs_repo
def uninstall(uri, package):
"""Uninstall a package"""
repo = pomu_active_repo()
if uri:
res = dispatcher.uninstall_package(repo, package).expect()
print(res)
else:
res = repo.remove_package(package).expect()
return res
@main.command()
@click.argument('package', required=True)
@click.option('--into', default=None,
help='Specify fetch destination')
def fetch(package, into):
"""Fetch a package into a directory"""
pkg = dispatcher.get_package(package).expect()
print('Fetched package', pkg, 'at', pkg.root)
print('Contents:')
for f in pkg.files:
print(' ', path.join(*f))
if into:
pkg.merge_into(into).expect()
print('Copied to', into, 'successfully')
@main.command()
@click.argument('package', required=True)
@needs_repo
def show(package):
"""Display installed package info"""
repo = pomu_active_repo()
category, _, name = package.rpartition('/')
name, _, slot = name.partition(':')
pkg = repo.get_package(name, category, slot).expect()
print('Package', pkg, 'version', pkg.version)
print('Merged into repository', repo.name, 'at', repo.root)
for f in pkg.files:
print(' ', path.join(*f))
if pkg.backend:
print('Backend:', pkg.backend.__name__)
print('Backend detailes:', pkg.backend)
def main_():
try:
main.main(standalone_mode=False)
except ResultException as e:
print(str(e))
if __name__ == '__main__':
main_()
|