~crunch.io/ubuntu/precise/codespeak-lib/unstable

« back to all changes in this revision

Viewing changes to doc/path.txt

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-08-01 16:24:01 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100801162401-g37v49d1p148alpm
Tags: 1.3.3-1
* New upstream release.
* Bump Standards-Version to 3.9.1.
* Fix typo in py.test manpage.
* Prefer Breaks: over Conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
Path implementations provided by ``py.path``
12
12
===============================================
13
13
 
14
 
.. _`local`: 
 
14
.. _`local`:
15
15
 
16
16
``py.path.local``
17
17
--------------------
82
82
=======================
83
83
 
84
84
All Path objects support a common set of operations, suitable
85
 
for many use cases and allowing to transparently switch the 
86
 
path object within an application (e.g. from "local" to "svnwc"). 
87
 
The common set includes functions such as `path.read()` to read all data 
88
 
from a file, `path.write()` to write data, `path.listdir()` to get a list 
 
85
for many use cases and allowing to transparently switch the
 
86
path object within an application (e.g. from "local" to "svnwc").
 
87
The common set includes functions such as `path.read()` to read all data
 
88
from a file, `path.write()` to write data, `path.listdir()` to get a list
89
89
of directory entries, `path.check()` to check if a node exists
90
90
and is of a particular type, `path.join()` to get
91
91
to a (grand)child, `path.visit()` to recursively walk through a node's
92
 
children, etc.  Only things that are not common on 'normal' filesystems (yet), 
 
92
children, etc.  Only things that are not common on 'normal' filesystems (yet),
93
93
such as handling metadata (e.g. the Subversion "properties") require
94
 
using specific APIs. 
 
94
using specific APIs.
95
95
 
96
96
Examples
97
97
---------------------------------
100
100
which also presents parts of the 'common' API, and shows some non-common
101
101
methods:
102
102
 
103
 
Searching `.txt` files 
 
103
Searching `.txt` files
104
104
..........................
105
105
 
106
106
Search for a particular string inside all files with a .txt extension in a
122
122
  >>> results
123
123
  ['textfile1.txt', 'textfile2.txt', 'textfile2.txt']
124
124
 
125
 
Working with Paths 
 
125
Working with Paths
126
126
.......................
127
127
 
128
128
This example shows the ``py.path`` features to deal with
141
141
  'baz/qux'
142
142
  >>> p2.bestrelpath(p1).replace(sep, '/')
143
143
  '../..'
144
 
  >>> p2.join(p2.bestrelpath(p1)) == p1 
 
144
  >>> p2.join(p2.bestrelpath(p1)) == p1
145
145
  True
146
146
  >>> p3 = p1 / 'baz/qux' # the / operator allows joining, too
147
147
  >>> p2 == p3
148
148
  True
149
 
  >>> p4 = p1 + ".py"  
 
149
  >>> p4 = p1 + ".py"
150
150
  >>> p4.basename == "bar.py"
151
151
  True
152
152
  >>> p4.ext == ".py"
185
185
  >>> file1.check(basename='file1') # we can use all the path's properties here
186
186
  True
187
187
 
188
 
Setting svn-properties 
 
188
Setting svn-properties
189
189
.......................
190
190
 
191
191
As an example of 'uncommon' methods, we'll show how to read and write
230
230
===================================
231
231
 
232
232
* The SVN path objects require the "svn" command line,
233
 
  there is currently no support for python bindings. 
 
233
  there is currently no support for python bindings.
234
234
  Parsing the svn output can lead to problems, particularly
235
 
  regarding if you have a non-english "locales" setting. 
 
235
  regarding if you have a non-english "locales" setting.
236
236
 
237
 
* While the path objects basically work on windows, 
 
237
* While the path objects basically work on windows,
238
238
  there is no attention yet on making unicode paths
239
 
  work or deal with the famous "8.3" filename issues. 
 
239
  work or deal with the famous "8.3" filename issues.
240
240
 
241
241
Future plans
242
242
============
243
243
 
244
244
The Subversion path implementations are based
245
 
on the `svn` command line, not on the bindings. 
246
 
It makes sense now to directly use the bindings. 
 
245
on the `svn` command line, not on the bindings.
 
246
It makes sense now to directly use the bindings.
247
247
 
248
 
Moreover, it would be good, also considering 
 
248
Moreover, it would be good, also considering
249
249
`execnet`_ distribution of programs, to
250
250
be able to manipulate Windows Paths on Linux
251
251
and vice versa.  So we'd like to consider
252
 
refactoring the path implementations 
 
252
refactoring the path implementations
253
253
to provide this choice (and getting rid
254
 
of platform-dependencies as much as possible). 
 
254
of platform-dependencies as much as possible).
255
255
 
256
 
There is some experimental small approach 
 
256
There is some experimental small approach
257
257
(``py/path/gateway/``) aiming at having
258
 
a convenient Remote Path implementation. 
 
258
a convenient Remote Path implementation.
259
259
 
260
260
There are various hacks out there to have
261
261
Memory-Filesystems and even path objects
262
 
being directly mountable under Linux (via `fuse`). 
263
 
However, the Path object implementations 
264
 
do not internally have a clean abstraction 
 
262
being directly mountable under Linux (via `fuse`).
 
263
However, the Path object implementations
 
264
do not internally have a clean abstraction
265
265
of going to the filesystem - so with some
266
 
refactoring it should become easier to 
 
266
refactoring it should become easier to
267
267
have very custom Path objects, still offering
268
 
the quite full interface without requiring 
269
 
to know about all details of the full path 
270
 
implementation. 
 
268
the quite full interface without requiring
 
269
to know about all details of the full path
 
270
implementation.
271
271
 
272
272
.. _`execnet`: execnet.html
273
273