Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 1 | |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 3 | <html><head><title>Python: module oauth2client.locked_file</title> |
| 4 | </head><body bgcolor="#f0f0f8"> |
| 5 | |
| 6 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| 7 | <tr bgcolor="#7799ee"> |
| 8 | <td valign=bottom> <br> |
| 9 | <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.locked_file</strong></big></big></font></td |
| 10 | ><td align=right valign=bottom |
| 11 | ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/clean/oauth2client/locked_file.py">/home/jcgregorio/projects/clean/oauth2client/locked_file.py</a></font></td></tr></table> |
| 12 | <p><tt>Locked file interface that should work on Unix and Windows pythons.<br> |
| 13 | <br> |
| 14 | This module first tries to use fcntl locking to ensure serialized access<br> |
| 15 | to a file, then falls back on a lock file if that is unavialable.<br> |
| 16 | <br> |
| 17 | Usage:<br> |
| 18 | f = <a href="#LockedFile">LockedFile</a>('filename', 'r+b', 'rb')<br> |
| 19 | f.open_and_lock()<br> |
| 20 | if f.is_locked():<br> |
| 21 | print 'Acquired filename with r+b mode'<br> |
| 22 | f.file_handle().write('locked data')<br> |
| 23 | else:<br> |
| 24 | print 'Aquired filename with rb mode'<br> |
| 25 | f.unlock_and_close()</tt></p> |
| 26 | <p> |
| 27 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 28 | <tr bgcolor="#aa55cc"> |
| 29 | <td colspan=3 valign=bottom> <br> |
| 30 | <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
| 31 | |
| 32 | <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
| 33 | <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="errno.html">errno</a><br> |
| 34 | <a href="fcntl.html">fcntl</a><br> |
| 35 | </td><td width="25%" valign=top><a href="logging.html">logging</a><br> |
| 36 | <a href="os.html">os</a><br> |
| 37 | </td><td width="25%" valign=top><a href="time.html">time</a><br> |
| 38 | </td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
| 39 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 40 | <tr bgcolor="#ee77aa"> |
| 41 | <td colspan=3 valign=bottom> <br> |
| 42 | <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| 43 | |
| 44 | <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| 45 | <td width="100%"><dl> |
| 46 | <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> |
| 47 | </font></dt><dd> |
| 48 | <dl> |
| 49 | <dt><font face="helvetica, arial"><a href="oauth2client.locked_file.html#LockedFile">LockedFile</a> |
| 50 | </font></dt></dl> |
| 51 | </dd> |
| 52 | <dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>) |
| 53 | </font></dt><dd> |
| 54 | <dl> |
| 55 | <dt><font face="helvetica, arial"><a href="oauth2client.locked_file.html#AlreadyLockedException">AlreadyLockedException</a> |
| 56 | </font></dt></dl> |
| 57 | </dd> |
| 58 | </dl> |
| 59 | <p> |
| 60 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 61 | <tr bgcolor="#ffc8d8"> |
| 62 | <td colspan=3 valign=bottom> <br> |
| 63 | <font color="#000000" face="helvetica, arial"><a name="AlreadyLockedException">class <strong>AlreadyLockedException</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr> |
| 64 | |
| 65 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 66 | <td colspan=2><tt>Trying to lock a file that has already been locked by the <a href="#LockedFile">LockedFile</a>.<br> </tt></td></tr> |
| 67 | <tr><td> </td> |
| 68 | <td width="100%"><dl><dt>Method resolution order:</dt> |
| 69 | <dd><a href="oauth2client.locked_file.html#AlreadyLockedException">AlreadyLockedException</a></dd> |
| 70 | <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> |
| 71 | <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd> |
| 72 | <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
| 73 | </dl> |
| 74 | <hr> |
| 75 | Data descriptors defined here:<br> |
| 76 | <dl><dt><strong>__weakref__</strong></dt> |
| 77 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 78 | </dl> |
| 79 | <hr> |
| 80 | Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> |
| 81 | <dl><dt><a name="AlreadyLockedException-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__init__">__init__</a>(...) initializes x; see x.__class__.__doc__ for signature</tt></dd></dl> |
| 82 | |
| 83 | <hr> |
| 84 | Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> |
| 85 | <dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#AlreadyLockedException-__new__">__new__</a>(S, ...) -> a new <a href="__builtin__.html#object">object</a> with type S, a subtype of T</tt></dl> |
| 86 | |
| 87 | <hr> |
| 88 | Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br> |
| 89 | <dl><dt><a name="AlreadyLockedException-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl> |
| 90 | |
| 91 | <dl><dt><a name="AlreadyLockedException-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl> |
| 92 | |
| 93 | <dl><dt><a name="AlreadyLockedException-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl> |
| 94 | |
| 95 | <dl><dt><a name="AlreadyLockedException-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br> |
| 96 | <br> |
| 97 | Use of negative indices is not supported.</tt></dd></dl> |
| 98 | |
| 99 | <dl><dt><a name="AlreadyLockedException-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl> |
| 100 | |
| 101 | <dl><dt><a name="AlreadyLockedException-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl> |
| 102 | |
| 103 | <dl><dt><a name="AlreadyLockedException-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl> |
| 104 | |
| 105 | <dl><dt><a name="AlreadyLockedException-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl> |
| 106 | |
| 107 | <dl><dt><a name="AlreadyLockedException-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__str__">__str__</a>() <==> str(x)</tt></dd></dl> |
| 108 | |
| 109 | <dl><dt><a name="AlreadyLockedException-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl> |
| 110 | |
| 111 | <hr> |
| 112 | Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br> |
| 113 | <dl><dt><strong>__dict__</strong></dt> |
| 114 | </dl> |
| 115 | <dl><dt><strong>args</strong></dt> |
| 116 | </dl> |
| 117 | <dl><dt><strong>message</strong></dt> |
| 118 | </dl> |
| 119 | </td></tr></table> <p> |
| 120 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 121 | <tr bgcolor="#ffc8d8"> |
| 122 | <td colspan=3 valign=bottom> <br> |
| 123 | <font color="#000000" face="helvetica, arial"><a name="LockedFile">class <strong>LockedFile</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 124 | |
| 125 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 126 | <td colspan=2><tt>Represent a file that has exclusive access.<br> </tt></td></tr> |
| 127 | <tr><td> </td> |
| 128 | <td width="100%">Methods defined here:<br> |
| 129 | <dl><dt><a name="LockedFile-__init__"><strong>__init__</strong></a>(self, filename, mode, fallback_mode, use_fcntl<font color="#909090">=True</font>)</dt><dd><tt>Construct a <a href="#LockedFile">LockedFile</a>.<br> |
| 130 | <br> |
| 131 | Args:<br> |
| 132 | filename: string, The path of the file to open.<br> |
| 133 | mode: string, The mode to try to open the file with.<br> |
| 134 | fallback_mode: string, The mode to use if locking fails.<br> |
| 135 | use_fcntl: string, Whether or not fcntl-based locking should be used.</tt></dd></dl> |
| 136 | |
| 137 | <dl><dt><a name="LockedFile-file_handle"><strong>file_handle</strong></a>(self)</dt><dd><tt>Return the file_handle to the opened file.</tt></dd></dl> |
| 138 | |
| 139 | <dl><dt><a name="LockedFile-filename"><strong>filename</strong></a>(self)</dt><dd><tt>Return the filename we were constructed with.</tt></dd></dl> |
| 140 | |
| 141 | <dl><dt><a name="LockedFile-is_locked"><strong>is_locked</strong></a>(self)</dt><dd><tt>Return whether we successfully locked the file.</tt></dd></dl> |
| 142 | |
| 143 | <dl><dt><a name="LockedFile-open_and_lock"><strong>open_and_lock</strong></a>(self, timeout<font color="#909090">=0</font>, delay<font color="#909090">=0.050000000000000003</font>)</dt><dd><tt>Open the file, trying to lock it.<br> |
| 144 | <br> |
| 145 | Args:<br> |
| 146 | timeout: float, The number of seconds to try to acquire the lock.<br> |
| 147 | delay: float, The number of seconds to wait between retry attempts.<br> |
| 148 | <br> |
| 149 | Raises:<br> |
| 150 | <a href="#AlreadyLockedException">AlreadyLockedException</a>: if the lock is already acquired.<br> |
| 151 | IOError: if the open fails.</tt></dd></dl> |
| 152 | |
| 153 | <dl><dt><a name="LockedFile-unlock_and_close"><strong>unlock_and_close</strong></a>(self)</dt><dd><tt>Unlock and close a file.</tt></dd></dl> |
| 154 | |
| 155 | <hr> |
| 156 | Data descriptors defined here:<br> |
| 157 | <dl><dt><strong>__dict__</strong></dt> |
| 158 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 159 | </dl> |
| 160 | <dl><dt><strong>__weakref__</strong></dt> |
| 161 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 162 | </dl> |
| 163 | </td></tr></table></td></tr></table><p> |
| 164 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 165 | <tr bgcolor="#55aa55"> |
| 166 | <td colspan=3 valign=bottom> <br> |
| 167 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 168 | |
| 169 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
| 170 | <td width="100%"><strong>__author__</strong> = 'cache@google.com (David T McWherter)'<br> |
| 171 | <strong>logger</strong> = <logging.Logger instance></td></tr></table><p> |
| 172 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 173 | <tr bgcolor="#7799ee"> |
| 174 | <td colspan=3 valign=bottom> <br> |
| 175 | <font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr> |
| 176 | |
| 177 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
| 178 | <td width="100%">cache@google.com (David T McWherter)</td></tr></table> |
| 179 | </body></html> |