Commit ec12932cec670281baf45b5a10c0519db113cc4b

Authored by antonygc91
1 parent 412319b8
Exists in master

update bulk upload

development.ini-dist
1 1 [app:main]
2 2 use = egg:LBBulk
3 3  
4   -pyramid.reload_templates = true
5   -pyramid.debug_authorization = false
6   -pyramid.debug_notfound = false
7   -pyramid.debug_routematch = false
8   -pyramid.default_locale_name = en
9   -pyramid.includes =
10   - pyramid_tm
11   -
12   -sqlalchemy.url = postgresql://rest:rest@localhost/lbbulk
13   -
14   -domain = http://api.brlight.org
15   -base_name = wmi
  4 +extract_dir = /tmp/extract-zip
  5 +json_filename = /zipmaluco/coleta.json
  6 +lightbase_url= http://0.0.0.0/api/basex/doc
16 7  
17 8 [server:main]
18 9 use = egg:waitress#main
... ...
lbbulk/__init__.py
1   -from pyramid.config import Configurator
2   -from sqlalchemy import engine_from_config
3   -from lbbulk.config.routing import make_routes
4   -from pyramid_restler import includeme
5 1  
6   -from lbbulk.model import Base, metadata, DBSession
  2 +from pyramid.config import Configurator
  3 +from lbbulk import config
7 4  
8 5  
9 6 def main(global_config, **settings):
10 7 """ This function returns a Pyramid WSGI application.
11 8 """
12   - config = Configurator(settings=settings)
13   - config.scan('lbbulk')
14   - engine = engine_from_config(settings, 'sqlalchemy.')
15   - DBSession.configure(bind=engine)
16   - Base.metadata.bind = engine
17   - includeme(config)
18   - config.include('pyramid_chameleon')
19   - make_routes(config)
20   - config.enable_POST_tunneling()
21   - return config.make_wsgi_app()
22 9 \ No newline at end of file
  10 + configurator = Configurator(settings=settings)
  11 +
  12 + config.setup_config(settings)
  13 + config.make_routes(configurator)
  14 + configurator.scan()
  15 +
  16 + return configurator.make_wsgi_app()
... ...
lbbulk/config.py 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +
  2 +def setup_config(settings):
  3 +
  4 + global EXTRACT_DIR
  5 + global JSON_FILENAME
  6 + global LIGHTBASE_URL
  7 +
  8 + EXTRACT_DIR = settings['extract_dir']
  9 + JSON_FILENAME = settings['json_filename']
  10 + LIGHTBASE_URL = settings['lightbase_url']
  11 +
  12 +def make_routes(cfg):
  13 +
  14 + from lbbulk.view import zip_upload
  15 +
  16 + cfg.add_route('zip_upload', 'zip_upload', request_method='POST')
  17 + cfg.add_view(view=zip_upload, route_name='zip_upload')
  18 +
... ...
lbbulk/config/__init__.py
... ... @@ -1 +0,0 @@
1   -# package
2 0 \ No newline at end of file
lbbulk/config/routing.py
... ... @@ -1,14 +0,0 @@
1   -# import lbbulk.model
2   -from lbbulk.model.BulkUpload import BulkUploadContextFactory
3   -from lbbulk.model.BulkSource import BulkSourceContextFactory
4   -from lbbulk.view.restfulview import RegCustomView
5   -
6   -def make_routes(config):
7   - """
8   - Create routes
9   - """
10   - config.add_static_view('static', 'static', cache_max_age=3600)
11   - config.add_route('home', '/')
12   - config.add_restful_routes('source', BulkSourceContextFactory)
13   - config.add_restful_routes('reg', BulkUploadContextFactory,
14   - view=RegCustomView)
lbbulk/model/BulkSource.py
... ... @@ -1,20 +0,0 @@
1   -from sqlalchemy import Table, Column, Integer, String
2   -from pyramid_restler.model import SQLAlchemyORMContext
3   -from lbbulk.model import Base, metadata, session
4   -
5   -
6   -bulk_source = Table('lb_bulk_source', metadata,
7   - Column('id_source', Integer, primary_key=True),
8   - Column('name_source', String, nullable=False)
9   - )
10   -
11   -
12   -# map to it
13   -class BulkSource(Base):
14   - __table__ = bulk_source
15   -
16   -class BulkSourceContextFactory(SQLAlchemyORMContext):
17   - entity = BulkSource
18   -
19   - def session_factory(self):
20   - return session
lbbulk/model/BulkUpload.py
... ... @@ -1,40 +0,0 @@
1   -from sqlalchemy import Table, Column, Integer, String, ForeignKey
2   -from requests import get
3   -from pyramid_restler.model import SQLAlchemyORMContext
4   -from lbbulk.model import Base, metadata, session
5   -import json
6   -
7   -
8   -bulk_upload = Table('lb_bulk_upload', metadata,
9   - Column('id_reg', Integer, primary_key=True),
10   - Column('external_key', String, nullable=False),
11   - Column('id_source', Integer,
12   - ForeignKey('lb_bulk_source.id_source'),
13   - nullable=False),
14   - extend_existing=True
15   - )
16   -
17   -# map to it
18   -class BulkUpload(Base):
19   - __table__ = bulk_upload
20   -
21   - def verifica_registro(data):
22   - # q = session.query(BulkUpload).filter_by(id_source=1, external_key=data['json_reg']['id_reg'] )
23   - get('localhost/')
24   - registro_existe = q.first()
25   - if sim:
26   - registro_existe = True
27   - else:
28   - registro_existe = False
29   - return registro_existe
30   -
31   -
32   -class BulkUploadContextFactory(SQLAlchemyORMContext):
33   - entity = BulkUpload
34   -
35   - def session_factory(self):
36   - return session
37   -
38   - def get_member_id_as_string(self, member):
39   - id = self.get_member_id(member)
40   - return json.dumps(id, cls=self.json_encoder)
41 0 \ No newline at end of file
lbbulk/model/__init__.py
... ... @@ -1,8 +0,0 @@
1   -from sqlalchemy import MetaData
2   -from sqlalchemy.ext.declarative import declarative_base
3   -from sqlalchemy.orm import scoped_session, sessionmaker
4   -
5   -metadata = MetaData()
6   -Base = declarative_base()
7   -DBSession = scoped_session(sessionmaker())
8   -session = DBSession
9 0 \ No newline at end of file
lbbulk/static/favicon.ico
No preview for this file type
lbbulk/static/footerbg.png

333 Bytes

lbbulk/static/headerbg.png

203 Bytes

lbbulk/static/ie6.css
... ... @@ -1,8 +0,0 @@
1   -* html img,
2   -* html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
3   -this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')",
4   -this.src = "static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
5   -this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')",
6   -this.runtimeStyle.backgroundImage = "none")),this.pngSet=true)
7   -);}
8   -#wrap{display:table;height:100%}
lbbulk/static/middlebg.png

2.73 KB

lbbulk/static/pylons.css
... ... @@ -1,372 +0,0 @@
1   -html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td
2   -{
3   - margin: 0;
4   - padding: 0;
5   - border: 0;
6   - outline: 0;
7   - font-size: 100%; /* 16px */
8   - vertical-align: baseline;
9   - background: transparent;
10   -}
11   -
12   -body
13   -{
14   - line-height: 1;
15   -}
16   -
17   -ol, ul
18   -{
19   - list-style: none;
20   -}
21   -
22   -blockquote, q
23   -{
24   - quotes: none;
25   -}
26   -
27   -blockquote:before, blockquote:after, q:before, q:after
28   -{
29   - content: '';
30   - content: none;
31   -}
32   -
33   -:focus
34   -{
35   - outline: 0;
36   -}
37   -
38   -ins
39   -{
40   - text-decoration: none;
41   -}
42   -
43   -del
44   -{
45   - text-decoration: line-through;
46   -}
47   -
48   -table
49   -{
50   - border-collapse: collapse;
51   - border-spacing: 0;
52   -}
53   -
54   -sub
55   -{
56   - vertical-align: sub;
57   - font-size: smaller;
58   - line-height: normal;
59   -}
60   -
61   -sup
62   -{
63   - vertical-align: super;
64   - font-size: smaller;
65   - line-height: normal;
66   -}
67   -
68   -ul, menu, dir
69   -{
70   - display: block;
71   - list-style-type: disc;
72   - margin: 1em 0;
73   - padding-left: 40px;
74   -}
75   -
76   -ol
77   -{
78   - display: block;
79   - list-style-type: decimal-leading-zero;
80   - margin: 1em 0;
81   - padding-left: 40px;
82   -}
83   -
84   -li
85   -{
86   - display: list-item;
87   -}
88   -
89   -ul ul, ul ol, ul dir, ul menu, ul dl, ol ul, ol ol, ol dir, ol menu, ol dl, dir ul, dir ol, dir dir, dir menu, dir dl, menu ul, menu ol, menu dir, menu menu, menu dl, dl ul, dl ol, dl dir, dl menu, dl dl
90   -{
91   - margin-top: 0;
92   - margin-bottom: 0;
93   -}
94   -
95   -ol ul, ul ul, menu ul, dir ul, ol menu, ul menu, menu menu, dir menu, ol dir, ul dir, menu dir, dir dir
96   -{
97   - list-style-type: circle;
98   -}
99   -
100   -ol ol ul, ol ul ul, ol menu ul, ol dir ul, ol ol menu, ol ul menu, ol menu menu, ol dir menu, ol ol dir, ol ul dir, ol menu dir, ol dir dir, ul ol ul, ul ul ul, ul menu ul, ul dir ul, ul ol menu, ul ul menu, ul menu menu, ul dir menu, ul ol dir, ul ul dir, ul menu dir, ul dir dir, menu ol ul, menu ul ul, menu menu ul, menu dir ul, menu ol menu, menu ul menu, menu menu menu, menu dir menu, menu ol dir, menu ul dir, menu menu dir, menu dir dir, dir ol ul, dir ul ul, dir menu ul, dir dir ul, dir ol menu, dir ul menu, dir menu menu, dir dir menu, dir ol dir, dir ul dir, dir menu dir, dir dir dir
101   -{
102   - list-style-type: square;
103   -}
104   -
105   -.hidden
106   -{
107   - display: none;
108   -}
109   -
110   -p
111   -{
112   - line-height: 1.5em;
113   -}
114   -
115   -h1
116   -{
117   - font-size: 1.75em;
118   - line-height: 1.7em;
119   - font-family: helvetica, verdana;
120   -}
121   -
122   -h2
123   -{
124   - font-size: 1.5em;
125   - line-height: 1.7em;
126   - font-family: helvetica, verdana;
127   -}
128   -
129   -h3
130   -{
131   - font-size: 1.25em;
132   - line-height: 1.7em;
133   - font-family: helvetica, verdana;
134   -}
135   -
136   -h4
137   -{
138   - font-size: 1em;
139   - line-height: 1.7em;
140   - font-family: helvetica, verdana;
141   -}
142   -
143   -html, body
144   -{
145   - width: 100%;
146   - height: 100%;
147   -}
148   -
149   -body
150   -{
151   - margin: 0;
152   - padding: 0;
153   - background-color: #fff;
154   - position: relative;
155   - font: 16px/24px NobileRegular, "Lucida Grande", Lucida, Verdana, sans-serif;
156   -}
157   -
158   -a
159   -{
160   - color: #1b61d6;
161   - text-decoration: none;
162   -}
163   -
164   -a:hover
165   -{
166   - color: #e88f00;
167   - text-decoration: underline;
168   -}
169   -
170   -body h1, body h2, body h3, body h4, body h5, body h6
171   -{
172   - font-family: NeutonRegular, "Lucida Grande", Lucida, Verdana, sans-serif;
173   - font-weight: 400;
174   - color: #373839;
175   - font-style: normal;
176   -}
177   -
178   -#wrap
179   -{
180   - min-height: 100%;
181   -}
182   -
183   -#header, #footer
184   -{
185   - width: 100%;
186   - color: #fff;
187   - height: 40px;
188   - position: absolute;
189   - text-align: center;
190   - line-height: 40px;
191   - overflow: hidden;
192   - font-size: 12px;
193   - vertical-align: middle;
194   -}
195   -
196   -#header
197   -{
198   - background: #000;
199   - top: 0;
200   - font-size: 14px;
201   -}
202   -
203   -#footer
204   -{
205   - bottom: 0;
206   - background: #000 url(footerbg.png) repeat-x 0 top;
207   - position: relative;
208   - margin-top: -40px;
209   - clear: both;
210   -}
211   -
212   -.header, .footer
213   -{
214   - width: 750px;
215   - margin-right: auto;
216   - margin-left: auto;
217   -}
218   -
219   -.wrapper
220   -{
221   - width: 100%;
222   -}
223   -
224   -#top, #top-small, #bottom
225   -{
226   - width: 100%;
227   -}
228   -
229   -#top
230   -{
231   - color: #000;
232   - height: 230px;
233   - background: #fff url(headerbg.png) repeat-x 0 top;
234   - position: relative;
235   -}
236   -
237   -#top-small
238   -{
239   - color: #000;
240   - height: 60px;
241   - background: #fff url(headerbg.png) repeat-x 0 top;
242   - position: relative;
243   -}
244   -
245   -#bottom
246   -{
247   - color: #222;
248   - background-color: #fff;
249   -}
250   -
251   -.top, .top-small, .middle, .bottom
252   -{
253   - width: 750px;
254   - margin-right: auto;
255   - margin-left: auto;
256   -}
257   -
258   -.top
259   -{
260   - padding-top: 40px;
261   -}
262   -
263   -.top-small
264   -{
265   - padding-top: 10px;
266   -}
267   -
268   -#middle
269   -{
270   - width: 100%;
271   - height: 100px;
272   - background: url(middlebg.png) repeat-x;
273   - border-top: 2px solid #fff;
274   - border-bottom: 2px solid #b2b2b2;
275   -}
276   -
277   -.app-welcome
278   -{
279   - margin-top: 25px;
280   -}
281   -
282   -.app-name
283   -{
284   - color: #000;
285   - font-weight: 700;
286   -}
287   -
288   -.bottom
289   -{
290   - padding-top: 50px;
291   -}
292   -
293   -#left
294   -{
295   - width: 350px;
296   - float: left;
297   - padding-right: 25px;
298   -}
299   -
300   -#right
301   -{
302   - width: 350px;
303   - float: right;
304   - padding-left: 25px;
305   -}
306   -
307   -.align-left
308   -{
309   - text-align: left;
310   -}
311   -
312   -.align-right
313   -{
314   - text-align: right;
315   -}
316   -
317   -.align-center
318   -{
319   - text-align: center;
320   -}
321   -
322   -ul.links
323   -{
324   - margin: 0;
325   - padding: 0;
326   -}
327   -
328   -ul.links li
329   -{
330   - list-style-type: none;
331   - font-size: 14px;
332   -}
333   -
334   -form
335   -{
336   - border-style: none;
337   -}
338   -
339   -fieldset
340   -{
341   - border-style: none;
342   -}
343   -
344   -input
345   -{
346   - color: #222;
347   - border: 1px solid #ccc;
348   - font-family: sans-serif;
349   - font-size: 12px;
350   - line-height: 16px;
351   -}
352   -
353   -input[type=text], input[type=password]
354   -{
355   - width: 205px;
356   -}
357   -
358   -input[type=submit]
359   -{
360   - background-color: #ddd;
361   - font-weight: 700;
362   -}
363   -
364   -/*Opera Fix*/
365   -body:before
366   -{
367   - content: "";
368   - height: 100%;
369   - float: left;
370   - width: 0;
371   - margin-top: -32767px;
372   -}
lbbulk/static/pyramid-small.png

6.88 KB

lbbulk/static/pyramid.png

32.3 KB

lbbulk/static/transparent.gif

49 Bytes

lbbulk/templates/mytemplate.pt
... ... @@ -1,80 +0,0 @@
1   -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2   -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal">
3   -<head>
4   - <title>The Pyramid Web Framework</title>
5   - <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
6   - <meta name="keywords" content="python web application" />
7   - <meta name="description" content="pyramid web application" />
8   - <link rel="shortcut icon" href="${request.static_url('lbbulk:static/favicon.ico')}" />
9   - <link rel="stylesheet" href="${request.static_url('lbbulk:static/pylons.css')}" type="text/css" media="screen" charset="utf-8" />
10   - <link rel="stylesheet" href="http://static.pylonsproject.org/fonts/nobile/stylesheet.css" media="screen" />
11   - <link rel="stylesheet" href="http://static.pylonsproject.org/fonts/neuton/stylesheet.css" media="screen" />
12   - <!--[if lte IE 6]>
13   - <link rel="stylesheet" href="${request.static_url('lbbulk:static/ie6.css')}" type="text/css" media="screen" charset="utf-8" />
14   - <![endif]-->
15   -</head>
16   -<body>
17   - <div id="wrap">
18   - <div id="top">
19   - <div class="top align-center">
20   - <div><img src="${request.static_url('lbbulk:static/pyramid.png')}" width="750" height="169" alt="pyramid"/></div>
21   - </div>
22   - </div>
23   - <div id="middle">
24   - <div class="middle align-center">
25   - <p class="app-welcome">
26   - Welcome to <span class="app-name">${project}</span>, an application generated by<br/>
27   - the Pyramid Web Framework.
28   - </p>
29   - </div>
30   - </div>
31   - <div id="bottom">
32   - <div class="bottom">
33   - <div id="left" class="align-right">
34   - <h2>Restful Views</h2>
35   - <ul class="links">
36   - <li>
37   - <a href="/lbbulk/reg">Registros</a>
38   - </li>
39   - <li>
40   - <a href="/lbbulk/source">Fontes de Dados</a>
41   - </li>
42   - <li>
43   - <hr>
44   - </li>
45   - </ul>
46   - </div>
47   - <div id="right" class="align-left">
48   - <h2>Pyramid links</h2>
49   - <ul class="links">
50   - <li>
51   - <a href="http://pylonsproject.org">Pylons Website</a>
52   - </li>
53   - <li>
54   - <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/#narrative-documentation">Narrative Documentation</a>
55   - </li>
56   - <li>
57   - <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/#reference-material">API Documentation</a>
58   - </li>
59   - <li>
60   - <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/#tutorials">Tutorials</a>
61   - </li>
62   - <li>
63   - <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/#detailed-change-history">Change History</a>
64   - </li>
65   - <li>
66   - <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/#sample-applications">Sample Applications</a>
67   - </li>
68   - <li>
69   - <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/#support-and-development">Support and Development</a>
70   - </li>
71   - <li>
72   - <a href="irc://irc.freenode.net#pyramid">IRC Channel</a>
73   - </li>
74   - </ul>
75   - </div>
76   - </div>
77   - </div>
78   - </div>
79   -</body>
80   -</html>
lbbulk/view.py 0 → 100644
... ... @@ -0,0 +1,95 @@
  1 +
  2 +import os
  3 +import cgi
  4 +import sys
  5 +import uuid
  6 +import json
  7 +import ijson
  8 +import shutil
  9 +import zipfile
  10 +import requests
  11 +from lbbulk import config
  12 +from multiprocessing import Process
  13 +from pyramid.view import view_config
  14 +from pyramid.response import Response
  15 +
  16 +@view_config(context=Exception)
  17 +def error_view(exc, request):
  18 + """ Customized Exception View
  19 + """
  20 + #l = traceback.extract_tb(request.exc_info[2])
  21 + exc_type, exc_obj, exc_tb = sys.exc_info()
  22 + exc_msg = exc_obj.args
  23 + if len(exc_obj.args) > 0:
  24 + exc_msg = exc_obj.args[0]
  25 + return Response(exc_msg, status=500)
  26 +
  27 +def zip_upload(request):
  28 +
  29 + file_ = request.params.get('file')
  30 +
  31 + if not isinstance(file_, cgi.FieldStorage):
  32 + return Response('File is not a zip file', status=500)
  33 + else:
  34 + ext_dir, json_file_path = extract_zip(file_)
  35 + process = Process(target=bulk_upload, args=(ext_dir, json_file_path,
  36 + config.LIGHTBASE_URL))
  37 + process.start()
  38 +
  39 + return Response('OK')
  40 +
  41 +def extract_zip(zfile):
  42 +
  43 + identifier = str(uuid.uuid4())
  44 + zpath = config.EXTRACT_DIR + '/' + identifier + '.zip'
  45 + zpath = os.path.abspath(zpath)
  46 +
  47 + try:
  48 + # write bytes to disk
  49 + with open(zpath, 'wb') as f:
  50 + f.write(zfile.file.read())
  51 + except Exception as e:
  52 + raise Exception('Error while uploading file! %s' % e)
  53 +
  54 + ext_dir = os.path.abspath(config.EXTRACT_DIR + '/' + identifier)
  55 +
  56 + if not os.path.exists(ext_dir):
  57 + os.makedirs(ext_dir)
  58 +
  59 + try:
  60 + # extract zip file
  61 + with zipfile.ZipFile(zpath, "r") as z:
  62 + z.extractall(ext_dir)
  63 + except Exception as e:
  64 + raise Exception('Error while extracting zip file! %s' % e)
  65 +
  66 + # remove zip file
  67 + os.remove(zpath)
  68 +
  69 + json_file_path = ext_dir + '/' + config.JSON_FILENAME
  70 + json_file_path = os.path.abspath(json_file_path)
  71 +
  72 + if not os.path.exists(json_file_path):
  73 + raise Exception('Could not find any json file in zip file: %s' %
  74 + config.JSON_FILENAME)
  75 +
  76 + return ext_dir, json_file_path
  77 +
  78 +def bulk_upload(ext_dir, file_path, url):
  79 +
  80 + file_ = open(file_path, 'rb')
  81 +
  82 + try:
  83 + objects = ijson.items(file_, 'results.item')
  84 + computers = (computer for computer in objects)
  85 + except Exception as e:
  86 + print('Error While Reading JSON file: %s' % e)
  87 +
  88 + for computer in computers:
  89 + document = json.dumps(computer)
  90 +
  91 + response = requests.post(url,
  92 + data={'value': document})
  93 +
  94 + shutil.rmtree(ext_dir)
  95 +
... ...
lbbulk/view/__init__.py
... ... @@ -1,7 +0,0 @@
1   -from pyramid.response import Response
2   -from pyramid.view import view_config
3   -
4   -
5   -@view_config(route_name='home', renderer='../templates/mytemplate.pt')
6   -def my_view(request):
7   - return {'project': 'LBBulk'}
8 0 \ No newline at end of file
lbbulk/view/restfulview.py
... ... @@ -1,74 +0,0 @@
1   -from pyramid_restler.view import RESTfulView
2   -from pyramid.response import Response
3   -from lbbulk.model.BulkUpload import BulkUpload
4   -import configparser
5   -import json
6   -import requests
7   -
8   -class RegCustomView(RESTfulView):
9   -
10   - def create_member(self):
11   - member = self.context.create_member(self._get_data())
12   - id = self.context.get_member_id_as_string(member)
13   - headers = {'Location': '/'.join((self.request.path, id))}
14   - return Response(status=201, headers=headers)
15   -
16   - def _get_data(self):
17   - """ Read json data from the post sent by some source """
18   - content_type = self.request.content_type
19   - if content_type == 'application/json':
20   - data = json.loads(self.request.body)
21   - elif content_type == 'application/x-www-form-urlencoded':
22   - data = dict(self.request.POST)
23   - else:
24   - data = self.request.params
25   - data = self.send_to_lightbase(data)
26   - # Must come with the external key as a value of
27   - # 'data.json_reg.id_reg'
28   - return data
29   -
30   - def send_to_lightbase(self, data):
31   - """ Sends the registers to a neo-light base and returns a dict
32   - with the external key and lighbase's id_reg """
33   - data['json_reg'] = json.loads(data['json_reg'])
34   - # converte os filhos pra dicts
35   -# existente = BulkUpload.verifica_registro(data)
36   - registro = self.is_error(data)
37   -# id_source = registro['id_source']
38   - id_source = 1
39   - external_key = registro['json_reg']['id_reg']
40   - registro['json_reg'].pop('id_reg', None)
41   - registro['json_reg'].pop('name_source', None)
42   - registro['json_reg'] = json.dumps(registro['json_reg'])
43   - url = self.get_url_lightbase()
44   -# if existente:
45   -# r = requests.put(url, data=registro)
46   -# id_reg = existente
47   -# data = None
48   - if False:
49   - pass
50   - else:
51   - r = requests.post(url, data=registro)
52   - id_reg = self.is_error_resp(r.json())
53   - data = {
54   - 'id_source':id_source,
55   - 'id_reg':id_reg,
56   - 'external_key':external_key
57   - }
58   - return data
59   -
60   - def get_url_lightbase(self): #TODO
61   - """ Returns url from config """
62   - domain = 'http://localhost/lightbase'
63   - base_name = 'wmi'
64   -# url = (settings['domain'] + '/' + settings['base_name'] + '/reg')
65   - url = (domain + '/' + base_name + '/reg')
66   - return url
67   -
68   - def is_error(self,data): #TODO
69   - return data
70   -
71   - def is_error_resp(self,r):
72   - if type(r) is dict:
73   - raise TypeError('Lightbase error ' + str(r['_status']) + ': ' + r['_error_message'])
74   - return r
production.ini-dist
1 1 [app:main]
2 2 use = egg:LBBulk
3 3  
4   -pyramid.reload_templates = false
5   -pyramid.debug_authorization = false
6   -pyramid.debug_notfound = false
7   -pyramid.debug_routematch = false
8   -pyramid.default_locale_name = en
9   -pyramid.includes =
10   - pyramid_tm
11   -
12   -sqlalchemy.url = postgresql://rest:rest@localhost/lbbulk
13   -
14   -domain = http://api.brlight.org
15   -base_name = wmi
  4 +extract_dir = /tmp/extract-zip
  5 +json_filename = /zipmaluco/coleta.json
  6 +lightbase_url= http://0.0.0.0/api/basex/doc
16 7  
17 8 [server:main]
18 9 use = egg:waitress#main
... ... @@ -34,11 +25,11 @@ keys = console
34 25 keys = generic
35 26  
36 27 [logger_root]
37   -level = WARN
  28 +level = INFO
38 29 handlers = console
39 30  
40 31 [logger_lbbulk]
41   -level = WARN
  32 +level = DEBUG
42 33 handlers =
43 34 qualname = lbbulk
44 35  
... ...
setup.py
... ... @@ -9,18 +9,9 @@ with open(os.path.join(here, &#39;CHANGES.txt&#39;)) as f:
9 9 CHANGES = f.read()
10 10  
11 11 requires = [
  12 + 'ijson',
12 13 'pyramid',
13   - 'SQLAlchemy',
14   - 'transaction',
15   - 'pyramid_tm',
16   - 'pyramid_debugtoolbar',
17   - 'zope.sqlalchemy',
18   - 'waitress',
19   - 'psycopg2',
20   - 'pyramid_restler',
21   - 'pyramid_chameleon',
22 14 'requests',
23   - 'chameleon'
24 15 ]
25 16  
26 17 setup(name='LBBulk',
... ...