/[theodore]/pyBB/modules/pathutils.pyc


UCC Code Repository

Contents of /pyBB/modules/pathutils.pyc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Tue Jan 29 14:32:01 2008 UTC (12 years, 2 months ago) by svn-admin
File MIME type: application/octet-stream
File size: 10609 byte(s)
Re-import of repository after repository database corruption.

1
2 ,‹Gc@sõdZdklZdkZdkZd#Zd„Zed„Zd„Z d„Z
3 d„Z d„Z d„Z d„Zd„ZeiiZeiiZeiiZd„Zd„Zd„Zdd„Zd„Zd „Zd!„Zed"„ZdS($sN
4 This module contains convenience functions for working with files and paths.
5 (s
6 generatorsNt readlinest
7 writelinest
8 readbinaryt writebinarytreadfilet writefilettslashtrelpathtsplitallt walkfilestwalkdirst walkemptydirst formatbytestfullcopyt import_pathcCs)t|dƒ}|iƒ}|iƒ|S(sPPassed a filename, it reads it, and returns a list of lines. (Read in text mode)trN(topentfilenamet
9 filehandleRtoutfiletclose(RRR((t./modules/pathutils.pyR.s
10  
11 cCsZt|dƒ}|o)g}|D]}||dq!~}n|i|ƒ|iƒdS(s°
12 Given a filename and a list of lines it writes the file. (In text mode)
13
14 If ``newline`` is ``True`` (default is ``False``) it adds a newline to each
15 line.
16 tws
17 N( RRRtnewlinet_[1]tinfiletlineRR(RRRRRR((RR5s ) cCs)t|dƒ}|iƒ}|iƒ|S(sIGiven a filename, read a file in binary mode. It returns a single string.trbN(RRRtreadtthisfileR(RRR((RRBs
18  
19 cCs*t|dƒ}|i|ƒ|iƒdS(s>Given a filename and a string, write the file in binary mode. twbN(RRRtwriteRR(RRR((RRIs cCs)t|dƒ}|iƒ}|iƒ|S(sGGiven a filename, read a file in text mode. It returns a single string.RN(RRRRRR(RRR((RROs
20  
21 cCs*t|dƒ}|i|ƒ|iƒdS(s;Given a filename and a string, write the file in text mode.RN(RRRRRR(RRR((RRVs cCsJ|o;|djo.|idƒ o|idƒ o |dSn|SdS(sµ
22 Add a trailing slash (``/``) to a path if it lacks one.
23
24 It doesn't use ``os.sep`` because you end up in trouble on windoze, when you
25 want separators for URLs.
26 t.t/s\N(tapathtendswith(R"((RR_s6 cCs=tii|ƒiddƒ}tii|ƒiddƒ}ttii|ƒƒ}t|ƒ}|dtii|dƒjo|Snd}xEt ||ƒD]4\}}|tii|ƒjoPn|d7}qŸWtigt|ƒ|}|||7}t|ƒdjo tiSntii|ŒiddƒSdS(s
27 Return the relative path between origin and dest.
28
29 If it's not possible return dest.
30
31
32 If they are identical return ``os.curdir``
33
34 Adapted from `path.py`_ by Jason Orendorff.
35
36
37 .. _path.py: http://www.jorendorff.com/articles/python/path/
38 s\R!iiN(tostpathtabspathtorigintreplacetdestRtnormcaset orig_listt dest_listtitzipt start_segtdest_segtpardirtlentsegmentstcurdirtjoin(R'R)R0R,R3R/R-R+((RRks$  !  cCs†g}xb|tijoQ|tijoA|}tii|ƒ\}}||joPn|i |ƒq W|i |ƒ|i
39 ƒ|S(sO
40 Return a list of the path components in loc. (Used by relpath_).
41
42 The first item in the list will be either ``os.curdir``, ``os.pardir``, empty,
43 or the root directory of loc (for example, ``/`` or ``C:\).
44
45 The other items in the list will be strings.
46
47 Adapted from path.py by Jason Orendorff.
48 N( tpartstlocR$R4R1tprevR%tsplittchildtappendtreverse(R7R8R6R:((RR—s
49    
50 ccsnxgti|ƒD]V}t||ƒ}t|ƒo|Vqt|ƒoxt|ƒD]
51 }|VqTWqqWdS(sŠ
52 walkfiles(D) -> iterator over files in D, recursively. Yields full file paths.
53
54 Adapted from path.py by Jason Orendorff.
55 N(
56 R$tlistdirtthisdirR:R5t thischildtisfiletisdirR tf(R>RBR?R:((RR ´s   ccsqxjti|ƒD]Y}t||ƒ}t|ƒoqqt|ƒo#xt|ƒD]
57 }|VqSW|VqqWdS(sm
58 Walk through all the subdirectories in a tree. Recursively yields directory
59 names (full paths).
60 N(
61 R$R=R>R:R5R?R@RAR
62 RB(R>RBR?R:((RR
63 Âs   ccsqti|ƒp|VnxRti|ƒD]A}t||ƒ}t|ƒoxt|ƒD]
64 }|VqWWq(q(WdS(s}
65 Recursively yield names of *empty* directories.
66
67 These are the only paths omitted when using ``walkfiles``.
68 N( R$R=R>R:R5R?RAR temptydir(R>R?R:RC((RR Ðs  c Ks.hdt<dt<dd<dd<dd<d t<}|djo
69 h}nx|D]}
70 ||
71 ||
72 <qZWx0|D](}|i|ƒp||||<qyqyW|d o
73 d
74 }nd }t
75 |ƒ\}}}|do|o)|d ot||ƒ||dSq*|p |doA|o|do|d |7}nt||ƒ||dSq*t|ƒ||dSn®d
76 } |o,|d o t|ƒ||dd } n|p|dp|oA|do|d |7}n| t|ƒ||dd 7} n| t|ƒ||dSdS(sâ
77 Given a file size as an integer, return a nicely formatted string that
78 represents the size. Has various options to control it's output.
79
80 You can pass in a dictionary of arguments or keyword arguments. Keyword
81 arguments override the dictionary and there are sensible defaults for options
82 you don't set.
83
84 Options and defaults are as follows :
85
86 * ``forcekb = False`` - If set this forces the output to be in terms
87 of kilobytes and bytes only.
88
89 * ``largestonly = True`` - If set, instead of outputting
90 ``1 Mbytes, 307 Kbytes, 478 bytes`` it outputs using only the largest
91 denominator - e.g. ``1.3 Mbytes`` or ``17.2 Kbytes``
92
93 * ``kiloname = 'Kbytes'`` - The string to use for kilobytes
94
95 * ``meganame = 'Mbytes'`` - The string to use for Megabytes
96
97 * ``bytename = 'bytes'`` - The string to use for bytes
98
99 * ``nospace = True`` - If set it outputs ``1Mbytes, 307Kbytes``,
100 notice there is no space.
101
102 Example outputs : ::
103
104 19Mbytes, 75Kbytes, 255bytes
105 2Kbytes, 0bytes
106 23.8Mbytes
107
108 .. note::
109
110 It currently uses the plural form even for singular.
111 tforcekbt largestonlytkilonametKbytestmeganametMbytestbytenametbytestnospacett is, N(tFalsetTruetdefaultconfigst
112 configdicttNonetconfigstentrytkeywordthas_keytspacet bytedividertsizeinttmbtkbRt stringroundtstrtoutstr( RZRRRTRQR\RVRXR[RR_RU((RR âs>$< 
113  
114    $cCs!||d}tt|dƒƒS(s[
115 Given a file size in either (mb, kb) or (kb, bytes) - round it
116 appropriately.
117 f1024.0iN(tmaintresttvalueR^tround(R`RaRb((RR]0scCs7t|dƒ\}}t|dƒ\}}|||fS(sï
118 Given an integer (probably a long integer returned by os.getsize() )
119 it returns a tuple of (megabytes, kilobytes, bytes).
120
121 This can be more easily converted into a formatted string to display the
122 size of the file.
123 iiN(tdivmodtnbytesR[t remainderR\R(ReR\R[RRf((RRY9scCsYdk}tiitii|ƒƒptitii|ƒƒn|i||ƒdS(s~
124 Copy file from src to dst.
125
126 If the dst directory doesn't exist, we will attempt to create it using makedirs.
127 N( tshutilR$R%RAtdirnametdsttmakedirstcopytsrc(RlRiRg((RR Gs
128  cCsÏtii|ƒ\}}tii|ƒ\}}tiid|ƒyt |ƒ}Wn t j
129 otid=‚nXtid=|oDtii|i ƒd}|i|ƒpt d||f‚qËn|S(s—
130 Import a file from the full path. Allows you to import from anywhere,
131 something ``__import__`` does not do.
132
133 If strict is ``True`` (the default), raise an ``ImportError`` if the module
134 is found in the "wrong" directory.
135
136 Taken from firedrop2_ by `Hans Nowak`_
137
138 .. _firedrop2: http://www.voidspace.org.uk/python/firedrop2/
139 .. _Hans Nowak: http://zephyrfalcon.org
140 is"Module '%s' found, but not in '%s'N(R$R%R9tfullpathRtsplitexttexttsystinsertt
141 __import__tmodulet ImportErrortstrictt__file__t
142 startswith(RmRuRsRRoR%((RRTs 
143 
144 (s readliness
145 writeliness
146 readbinarys writebinarysreadfiles writefilestslashsrelpathssplitalls walkfilesswalkdirss walkemptydirss formatbytessfullcopys import_path(t__doc__t
147 __future__t
148 generatorsR$Rpt__all__RRORRRRRRRRR%R5RAR@R R
149 R RSR R]RYR RPR(R]RRRR R@RR{RYRRzRRRpRR5R RARRR R
150 R$R ((Rt?s0        ,        N 

Properties

Name Value
svn:mime-type application/octet-stream

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26