-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrepopaths.py
More file actions
executable file
·101 lines (75 loc) · 2.4 KB
/
Copy pathrepopaths.py
File metadata and controls
executable file
·101 lines (75 loc) · 2.4 KB
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
#!/usr/bin/env python3
# pkgs.void - web catalog of Void Linux packages.
# Copyright (C) 2019-2023 Piotr Wójcik <chocimier@tlen.pl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import sys
from thirdparty import plistop
DATADIR = 'data'
def directory_name(repo):
result = ''
if 'musl/' in repo:
result += 'musl_'
for i in ['multilib', 'nonfree', 'debug', 'bootstrap']:
if i in repo:
result += i + '_'
result += repo.rpartition('/')[-1]
return result
def rsync_path(repo):
result = ''
for part in repo.split('/')[:-1]:
result += part + '/'
return result
def rsync_filename(path):
return 'rsync-' + path.strip('/').replace('/', '_')
def rsync_load(repo):
filename = rsync_filename(rsync_path(repo))
return open(os.path.join(DATADIR, filename))
def index_path(repo):
return os.path.join(DATADIR, directory_name(repo), 'index.plist')
def load_repo(path):
try:
with open(path, 'rb') as xml_file:
plist_index = plistop.parse(xml_file)
return plist_index
except FileNotFoundError:
return None
_COMMANDS = {
'directory_name': directory_name,
'rsync_path': rsync_path,
'rsync_filename': rsync_filename,
}
def usage(script_name, bad_command=None):
def show(string):
print(string, file=sys.stderr)
show(f'usage: {script_name} <command> path')
if bad_command is not None:
show(f'{bad_command} is not known command')
show('commands:')
for command in _COMMANDS:
show(f' {command}')
def main(*args):
try:
script_name, command, arg = args
except ValueError:
usage(args[0])
sys.exit(1)
try:
func = _COMMANDS[command]
except KeyError:
usage(script_name, command)
sys.exit(1)
print(func(arg))
if __name__ == '__main__':
main(*sys.argv)