File: module-sqlobject.util.csvimport.html

package info (click to toggle)
sqlobject 3.1.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,280 kB
  • ctags: 17,912
  • sloc: python: 16,713; sh: 18; makefile: 13
file content (159 lines) | stat: -rw-r--r-- 7,257 bytes parent folder | download
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

  <h1 class="pudge-member-page-heading">
    <tt>csvimport</tt>
  </h1>
  <h4 class="pudge-member-page-subheading">
    Import from a CSV file or directory of files.
  </h4>
  <p class="pudge-member-parent-link">
    <small>
    The csvimport module is accessible via the
    <a href="module-sqlobject.util.html">
      <tt>sqlobject.util</tt>
    </a> module.
    </small>
  </p>
  <div id="pudge-section-nav">
  <ul>
    <li>
      <a href="#attributes" class="pudge-section-link">
        Attributes (1)
      </a>
    </li><li>
      <a href="#functions" class="pudge-section-link">
        Functions (3)
      </a>
    </li><li>
      <span class="pudge-missing-section-link">
        Classes
      </span>
    </li><li>
      <span class="pudge-missing-section-link">
        Modules
      </span>
    </li>
    <li>
      <a href="module-sqlobject.util.csvimport-index.html" class="pudge-section-link">
        Index
      </a>
    </li>
    <li>
      <a href="sqlobject/util/csvimport.py.html" class="pudge-section-link">
        Source
      </a>
    </li>
  </ul>
  </div>
  <div style="clear: left"></div>
  <div class="rst pudge-module-doc">
    <p>CSV files should have a header line that lists columns.  Headers can
also be appended with <tt class="docutils literal">:type</tt> to indicate the type of the field.
<tt class="docutils literal">escaped</tt> is the default, though it can be overridden by the importer.
Supported types:</p>
<dl class="docutils">
<dt><tt class="docutils literal">:python</tt>:</dt>
<dd>A python expression, run through <tt class="docutils literal">eval()</tt>.  This can be a
security risk, pass in <tt class="docutils literal">allow_python=False</tt> if you don't want to
allow it.</dd>
<dt><tt class="docutils literal">:int</tt>:</dt>
<dd>Integer</dd>
<dt><tt class="docutils literal">:float</tt>:</dt>
<dd>Float</dd>
<dt><tt class="docutils literal">:str</tt>:</dt>
<dd>String</dd>
<dt><tt class="docutils literal">:escaped</tt>:</dt>
<dd>A string with backslash escapes (note that you don't put quotation
marks around the value)</dd>
<dt><tt class="docutils literal">:base64</tt>:</dt>
<dd>A base64-encoded string</dd>
<dt><tt class="docutils literal">:date</tt>:</dt>
<dd>ISO date, like YYYY-MM-DD; this can also be <tt class="docutils literal">NOW+days</tt> or
<tt class="docutils literal"><span class="pre">NOW-days</span></tt></dd>
<dt><tt class="docutils literal">:datetime</tt>:</dt>
<dd>ISO date/time like YYYY-MM-DDTHH:MM:SS (either T or a space can be
used to separate the time, and seconds are optional).  This can
also be <tt class="docutils literal">NOW+seconds</tt> or <tt class="docutils literal"><span class="pre">NOW-seconds</span></tt></dd>
<dt><tt class="docutils literal">:bool</tt>:</dt>
<dd>Converts true/false/yes/no/on/off/1/0 to boolean value</dd>
<dt><tt class="docutils literal">:ref</tt>:</dt>
<dd>This will be resolved to the ID of the object named in this column
(None if the column is empty).  @@: Since there's no ordering,
there's no way to promise the object already exists.</dd>
</dl>
<p>You can also get back references to the objects if you have a special
<tt class="docutils literal">[name]</tt> column.</p>
<p>Any column named <tt class="docutils literal">[comment]</tt> or with no name will be ignored.</p>
<p>In any column you can put <tt class="docutils literal">[default]</tt> to exclude the value and use
whatever default the class wants.  <tt class="docutils literal">[null]</tt> will use NULL.</p>
<p>Lines that begin with <tt class="docutils literal">[comment]</tt> are ignored.</p>
  </div>
  <hr>
    <a name="attributes"></a>
    <h2>Attributes</h2>
    <div class="pudge-member name">
    <a name="__package__"></a>
    <h4 class="pudge-member-name"><span class="prefix">a</span>
      <tt><a href="module-sqlobject.util.csvimport.html#__package__" class="pudge-obj-link">__package__</a></tt></h4>
    <div class="pudge-section rst">
      <pre>'sqlobject.util'</pre>
    </div>
  </div>
    <a name="functions"></a>
    <h2>Functions</h2>
    <div class="pudge-member routine ">
    <a name="create_data"></a>
    <h4 class="pudge-member-name"><span class="prefix">f</span>
      <tt><a href="module-sqlobject.util.csvimport.html#create_data" class="pudge-obj-link">create_data</a>(data, class_getter, keyorder=None)</tt>
      <a href="sqlobject/util/csvimport.py.html?f=72&amp;l=139#72" title="View Source">...</a>
    </h4>
    <div class="pudge-section rst">
    <p class="pudge-member-blurb">
      Create the <tt class="docutils literal">data</tt>, which is the return value from
<tt class="docutils literal">load_csv()</tt>.  Classes will be resolved with the callable
<tt class="docutils literal">class_getter</tt>; or if <tt class="docutils literal">class_getter</tt> is a module then the
class names will be attributes of that.
    </p>
    <p>Returns a dictionary of <tt class="docutils literal">{object_name: object(s)}</tt>, using the
names from the <tt class="docutils literal">[name]</tt> columns (if there are any).  If a name
is used multiple times, you get a list of objects, not a single
object.</p>
<p>If <tt class="docutils literal">keyorder</tt> is given, then the keys will be retrieved in that
order.  It can be a list/tuple of names, or a sorting function.
If not given and <tt class="docutils literal">class_getter</tt> is a module and has a
<tt class="docutils literal">soClasses</tt> function, then that will be used for the order.</p>
    </div>
  </div><div class="pudge-member routine ">
    <a name="load_csv_from_directory"></a>
    <h4 class="pudge-member-name"><span class="prefix">f</span>
      <tt><a href="module-sqlobject.util.csvimport.html#load_csv_from_directory" class="pudge-obj-link">load_csv_from_directory</a>(directory, allow_python=True, default_type='escaped', allow_multiple_classes=True)</tt>
      <a href="sqlobject/util/csvimport.py.html?f=141&amp;l=166#141" title="View Source">...</a>
    </h4>
    <div class="pudge-section rst">
    <p class="pudge-member-blurb">
      Load the data from all the files in a directory.  Filenames
indicate the class, with <tt class="docutils literal">general.csv</tt> for data not associated
with a class.  Return data just like <tt class="docutils literal">load_csv</tt> does.
    </p>
    <p>This might cause problems on case-insensitive filesystems.</p>
    </div>
  </div><div class="pudge-member routine ">
    <a name="load_csv"></a>
    <h4 class="pudge-member-name"><span class="prefix">f</span>
      <tt><a href="module-sqlobject.util.csvimport.html#load_csv" class="pudge-obj-link">load_csv</a>(csvreader, allow_python=True, default_type='escaped', default_class=None, allow_multiple_classes=True)</tt>
      <a href="sqlobject/util/csvimport.py.html?f=168&amp;l=227#168" title="View Source">...</a>
    </h4>
    <div class="pudge-section rst">
    <p class="pudge-member-blurb">
      Loads the CSV file, returning a list of dictionaries with types
coerced.
    </p>
    </div>
  </div>
  <p>
    <small>
    See 
    <a href="sqlobject/util/csvimport.py.html" title="sqlobject/util/csvimport.py:0">the source</a>
    for more information.
    </small>
  </p>