@@ -10,65 +10,74 @@ Usecases
10
10
11
11
We are here working from :doc: `data_pkg_discuss `
12
12
13
- Distribution types
14
- ==================
13
+ Prundles
14
+ ========
15
15
16
- The most common type of distribution is a *file-system * distribution, that is,
17
- a distribution that can return content from passed filenames, as if it were a
18
- file-system. The examples below should make this clearer.
16
+ See :ref: `prundle `.
19
17
20
- An *local path * distribution is a file-system distribution with content stored
21
- in files in a directory accessible on the local filesystem. We could also call
22
- this a *local path * distribution type.
18
+ An *local path * format prundle is a directory on the local file system with prundle data stored in files in a
19
+ on the local filesystem.
23
20
24
21
Examples
25
22
========
26
23
27
- Create distribution
28
- -------------------
24
+ We'll call our package `dang ` - data package new generation.
29
25
30
- ::
26
+ Create local-path prundle
27
+ -------------------------
31
28
32
- >>> import os
33
- >>> import dpkg
34
- >>> dst = dpkg.LocalPathDistribution.initialize(name='my-package', path=/a/path')
35
- >>> dst.name
36
- 'my-package'
37
- >>> dst.version
38
- '0'
39
- >>> dst.path == os.path.abspath(/a/path')
40
- True
41
- >>> os.listdir(/a/path')
42
- ['meta.ini']
29
+ >>> import os
30
+ >>> import tempfile
31
+ >>> pth = tempfile.mkdtemp() # temporary directory
43
32
44
- The local path distribution here is just the set of files in the `` a/path `` directory.
33
+ Make a pinstance object
45
34
46
- The call to the ``initialize `` class method above creates the directory if it
47
- does not exist, and writes a bare ``meta.ini `` file to the directory, with the
48
- given ``name ``, and default version of ``0 ``.
35
+ >>> from dang import Pinstance
36
+ >>> pri = Prundle(name = ' my-package' )
37
+ >>> pri.pkg_name
38
+ 'my-package'
39
+ >>> pri.meta
40
+ {}
49
41
50
- Use local path distribution
51
- ---------------------------
42
+ Now we make a prundle. First a directory to contain it
52
43
53
- ::
44
+ >>> import os
45
+ >>> import tempfile
46
+ >>> pth = tempfile.mkdtemp() # temporary directory
54
47
55
- >>> dst = dpkg.LocalPathDistribution.from_path(path=/a/path')
56
- >>> dst.name
57
- 'my-package'
48
+ >>> from dang.prundle import LocalPathPrundle
49
+ >>> prun = LocalPathPrundle(pri, pth)
50
+
51
+ At the moment there's nothing in the directory. The 'write' method will write
52
+ the meta information - here just the package name.
53
+
54
+ >>> prun.write() # writes meta.ini file
55
+ >>> os.listdir(pth)
56
+ ['meta.ini']
57
+
58
+ The local path prundle data is just the set of files in the temporary directory
59
+ named in ``pth `` above.
60
+
61
+ Now we've written the package, we can get it by a single call that reads in the
62
+ ``meta.ini `` file:
58
63
59
- Getting content
60
- ---------------
64
+ >>> prun_back = LocalPathPrundle.from_path(pth)
65
+ >>> prun_back.pkg_name
66
+ 'my-package'
61
67
62
- The file-system distribution types can return content by file names.
68
+ Getting prundle data
69
+ --------------------
63
70
64
- For example, for the local path ``dst `` distribution objects we have seen so
71
+ The file-system prundle formats can return content by file names.
72
+
73
+ For example, for the local path ``prun `` distribution objects we have seen so
65
74
far, the following should work::
66
75
67
- >>> fobj = dst .get_fileobj('a_file.txt')
76
+ >>> fobj = prun .get_fileobj('a_file.txt')
68
77
69
78
In fact, local path distribution objects also have a ``path `` attribute::
70
79
71
- >>> fname = os.path.join(dst .path, 'a_file.txt')
80
+ >>> fname = os.path.join(prun .path, 'a_file.txt')
72
81
73
82
The ``path `` attribute might not make sense for objects with greater abstraction
74
83
over the file-system - for example objects encapsulating web content.
@@ -77,38 +86,39 @@ over the file-system - for example objects encapsulating web content.
77
86
Discovery
78
87
*********
79
88
80
- So far we only have distribution objects. In order for a program to use a
81
- distribution object it has to know where the distribution is.
89
+ So far, in order to create a prundle object, we have to know where the prundle
90
+ is (the path).
91
+
92
+ We want to be able to tell the system where prundles are - and the system will
93
+ then be able to return a prundle on request - perhaps by package name. The
94
+ system here is answering a :ref: `prundle-discovery ` query.
82
95
83
- We will then want to ask our packaging system whether it knows about the
84
- distribution we are interested in. This is a * discovery query * .
96
+ We will then want to ask our packaging system whether it knows about the prundle
97
+ we are interested in.
85
98
86
99
Discovery sources
87
100
=================
88
101
89
102
A discovery source is an object that can answer a discovery query.
90
103
Specifically, it is an object with a ``discover `` method, like this::
91
104
92
- >>> dsrc = dpkg.get_source('local-system')
105
+ >>> import dang
106
+ >>> dsrc = dang.get_source('local-system')
93
107
>>> dquery_result = dsrc.discover('my-package', version='0')
94
- >>> dquery_result.distribution.name
108
+ >>> dquery_result[0].pkg_name
95
109
'my-package'
96
110
>>> dquery_result = dsrc.discover('implausible-pkg', version='0')
97
- >>> dquery_result.distribution is None
98
- True
99
-
100
- The ``discover `` method returns a discovery query result. This result contains
101
- a distribution object if it knows about the distribution with the given name and
102
- version; the distribution in the query is None otherwise.
111
+ >>> len(dquery_result)
112
+ 0
103
113
104
114
The discovery version number spec may allow comparison operators, as for
105
115
``distutils.version.LooseVersion ``::
106
116
107
117
>>> res = dsrc.discover(name='my-package', version='>=0')
108
- >>> dst = rst.distribution
109
- >>> dst.name
118
+ >>> prun = rst[0]
119
+ >>> prun.pkg_name
110
120
'my-package'
111
- >>> dst. version
121
+ >>> prun.meta[' version']
112
122
'0'
113
123
114
124
Default discovery sources
@@ -137,51 +147,50 @@ from a list of sources. Something like this::
137
147
>>> local_usr = dpkg.get_source('local-user')
138
148
>>> src_pool = dpkg.SourcePool((local_usr, local_sys))
139
149
>>> dq_res = src_pool.discover('my-package', version='0')
140
- >>> dq_res.distribution.name
150
+ >>> dq_res[0].pkg_name
141
151
'my-package'
142
152
143
153
We'll often want to do exactly this, so we'll add this source pool to those that
144
154
can be returned from our ``get_source `` convenience function::
145
155
146
156
>>> src_pool = dpkg.get_source('local-pool')
147
157
148
- Register a distribution
149
- =======================
158
+ Register a prundle
159
+ ==================
150
160
151
- In order to register a distribution , we need a distribution object and a
161
+ In order to register a prundle , we need a prundle object and a
152
162
discovery source::
153
163
154
- >>> dst = dpkg.LocalPathDistribution.from_path(path=/a/path')
155
- >>> local_usr = dpkg.get_source('local-user')
156
- >>> local_usr.register(dst)
164
+ >>> from dang.prundle import LocalPathPrundle
165
+ >>> prun = LocalPathDistribution.from_path(path=/a/path')
166
+ >>> local_usr = dang.get_source('local-user')
167
+ >>> local_usr.register(prun)
157
168
158
169
Let us then write the source to disk::
159
170
160
- >>> local_usr.save ()
171
+ >>> local_usr.write ()
161
172
162
173
Now, when we start another process as the same user, we can do this::
163
174
164
- >>> import dpkg
165
- >>> local_usr = dpkg .get_source('local-user')
166
- >>> dst = local_usr.discover('my-package', '0')
175
+ >>> import dang
176
+ >>> local_usr = dang .get_source('local-user')
177
+ >>> prun = local_usr.discover('my-package', '0')[0]
167
178
168
179
**************
169
180
Implementation
170
181
**************
171
182
172
183
Here are some notes. We had the hope that we could implement something that
173
184
would be simple enough that someone using the system would not need our code,
174
- but could work from the specification. In practice we hope to be able get away
175
- with something that uses ``ini `` format files as base storage, because these are
176
- fairly standard and have support in the python standard library since way back.
185
+ but could work from the specification.
177
186
178
- Local path distributions
179
- ========================
187
+ Local path prundles
188
+ ===================
180
189
181
- As implied above, these are directories accessible on the local filesystem.
182
- The directory needs to give information about the distribution name and version.
183
- An ``ini `` file is probably enough for this - something like a `` meta.ini `` file
184
- in the directory with::
190
+ These are directories accessible on the local filesystem. The directory needs
191
+ to give information about the prundle name and optionally, version, tag,
192
+ revision id and maybe other metadata. An ``ini `` file is probably enough for
193
+ this - something like a `` meta.ini `` file in the directory with::
185
194
186
195
[DEFAULT]
187
196
name = my-package
@@ -192,11 +201,8 @@ might be enough to get started.
192
201
Discovery sources
193
202
=================
194
203
195
- The discovery source has to be able to return distribution objects for the
196
- distributions it knows about. A discovery source might only be able to handle
197
- local path distributions, in which case all it needs to know about a
198
- distribution is the (name, version, path). So, a local path discovery source
199
- could be stored on disk as an ``ini `` file as well::
204
+ The discovery source has to be able to return prundle objects for the
205
+ prundles it knows about.
200
206
201
207
[my-package]
202
208
0 = /some/path
0 commit comments