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
|
# Copyright (C) 2004 Aaron Bentley
# <aaron.bentley@utoronto.ca>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import pybaz as arch
__docformat__ = "restructuredtext"
__doc__ = "Tools to generate and interpret Arch pathnames"
def determine_path(thing, thingname=None, archivelocation=None):
"""
Converts a name to its location.
:param thing: an archive, version, revision or other name
:type thing: anything a NameParser can parse
:param thingname: Optional NameParser version of the name
:type thingname: `arch.NameParser`
:param archivelocation: Optional location of the archive. Required if \
thing has no archive name.
:rtype: str
"""
if thingname is None:
thingname=arch.NameParser(thing)
if archivelocation is None:
archivelocation=arch.Archive(thingname.get_archive()).location
path=archivelocation
if not thingname.has_category():
return path
path+="/"+thingname.get_category()
if not thingname.has_package():
return path
path+="/"+thingname.get_package()
if not thingname.has_version():
return path
path+="/"+thingname.get_package_version()
if not thingname.has_patchlevel():
return path
path+="/"+thingname.get_patchlevel()
return path
class NotARevision(Exception):
"""Raise if a name is not a revision name, though it should be."""
pass
def determine_import_path(thing):
return determine_file_path(thing, ".src.tar.gz")
def determine_cacherev_path(thing):
return determine_file_path(thing, ".tar.gz")
def determine_file_path(thing, extension):
thingname=arch.NameParser(thing)
if not thingname.has_patchlevel():
raise NotARevision
return determine_path(thing, thingname)+"/"+thingname.get_nonarch()+extension
def determine_patch_path(thing):
return determine_file_path(thing, ".patches.tar.gz")
def determine_log_path(thing):
return determine_path(thing)+"/log"
def determine_continuation_path(thing):
return determine_path(thing)+"/CONTINUATION"
def decode_path(path):
pathcomponents = path.rstrip("/").split("/")
if arch.NameParser.is_patchlevel(pathcomponents[-1]):
is_revision = True
else:
is_revision = False
if is_revision:
if not is_version_path(pathcomponents[:-1]):
raise CantDecode(path)
nonarch = pathcomponents[-2]+"--"+pathcomponents[-1]
arch_loc = "/".join(pathcomponents[:-4])
else:
if not is_version_path(pathcomponents):
raise CantDecode(path)
nonarch = pathcomponents[-1]
arch_loc = "/".join(pathcomponents[:-3])
return arch_loc, nonarch
def is_version_path(pathcomponents):
"""
Determines whether a file path is a plausible version path.
:param pathcomponents: The components of the file path
:type pathcomponents: List of str
:rtype: bool
"""
if not pathcomponents[-1].startswith(pathcomponents[-2]+"--"):
return False
elif not pathcomponents[-2].startswith(pathcomponents[-3]):
return False
else:
return True
def arch_name_from_path(path):
for myarch in arch.iter_archives():
if myarch.location == path:
return myarch.official_name
tmparch = arch.register_archive('tmparch@example.com', path)
name = tmparch.official_name
tmparch.unregister()
return name
class CantDecode(Exception):
"""
Raise to indicate that a path could not be decoded.
"""
def __init__(self, path):
self.path=path
message = "Path \"%s\" could not be decoded." % self.path
Exception.__init__(self, message)
def full_path_decode(path):
arch_loc, nonarch = decode_path(path)
archive = arch_name_from_path(arch_loc)
fq_name = arch.NameParser("%s/%s" % (archive, nonarch))
if fq_name.is_version():
return arch.Version(fq_name), arch_loc
elif fq_name.has_patchlevel():
return arch.Revision(fq_name), arch_loc
else:
raise CantDecode(path)
def is_url_path(spec):
"""
Determines whether the provided spec is a path or archive URL.
:param spec: the string that may be a path or archive URL
:type spec: str
"""
if spec.startswith("/") or spec.startswith("http://"):
return True
elif spec.startswith("sftp://") or spec.startswith ("ftp://"):
return True
elif spec.startswith("ws_ftp://"):
return True
else:
return False
def tree_log(dir, revision):
"""Return the full path to a patchlog file.
:param dir: The tree-root directory
:type dir: str
:param revision: The revision of the log to get
:type revision: `arch.Revision`
"""
return "%s/{arch}/%s/%s/%s/%s/patch-log/%s" % (dir,
revision.category.nonarch,
revision.branch.nonarch,
revision.version.nonarch,
revision.archive,
revision.patchlevel)
# arch-tag: 5f0fccc4-9681-4652-bb79-10560f2da13e
|