Commit 279aa412e31ce6bb325241468b03ec411c267dc0

Authored by carol15022
Committed by Sergio Oliveira
1 parent 95aa1b8d
Exists in trac_indexing

Documentation of Trac Data API.

Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
colab/proxy/trac/data_api.py
  1 +# -*- coding: utf-8 -*-
1 from re import match 2 from re import match
2 3
3 from django.db import connections 4 from django.db import connections
@@ -9,6 +10,10 @@ from colab.proxy.utils.proxy_data_api import ProxyDataAPI @@ -9,6 +10,10 @@ from colab.proxy.utils.proxy_data_api import ProxyDataAPI
9 class TracDataAPI(ProxyDataAPI): 10 class TracDataAPI(ProxyDataAPI):
10 11
11 def fetch_data(self): 12 def fetch_data(self):
  13 + """ This is the pricipal method whose function is just make the call the
  14 + other methods.
  15 +
  16 + """
12 connection = connections['trac'] 17 connection = connections['trac']
13 cursor = connection.cursor() 18 cursor = connection.cursor()
14 self.fetch_data_wiki(cursor) 19 self.fetch_data_wiki(cursor)
@@ -17,6 +22,17 @@ class TracDataAPI(ProxyDataAPI): @@ -17,6 +22,17 @@ class TracDataAPI(ProxyDataAPI):
17 self.fetch_data_revision(cursor) 22 self.fetch_data_revision(cursor)
18 23
19 def fetch_data_attachment(self, empty_cursor): 24 def fetch_data_attachment(self, empty_cursor):
  25 + """ This method is responsible for seeking the attachment data in
  26 +        trac database and transfer them to the colab database.
  27 +
  28 + :param empty_cursor: A cursor coming from connectinos, it is necessary
  29 +         import the connections library from django.db, with it we can run
  30 +         sql commands.
  31 +
  32 +        :returns: Return is an attachment object with your saved data
  33 +         in the colab database.
  34 +
  35 + """
20 attachment = Attachment() 36 attachment = Attachment()
21 cursor = self.attachment_cursor(empty_cursor) 37 cursor = self.attachment_cursor(empty_cursor)
22 attachment_dict = self.dictfetchall(cursor) 38 attachment_dict = self.dictfetchall(cursor)
@@ -38,6 +54,17 @@ class TracDataAPI(ProxyDataAPI): @@ -38,6 +54,17 @@ class TracDataAPI(ProxyDataAPI):
38 attachment.save() 54 attachment.save()
39 55
40 def fetch_data_revision(self, empty_cursor): 56 def fetch_data_revision(self, empty_cursor):
  57 + """ This method is responsible for seeking the revision data in
  58 +        trac database and transfer them to the colab database.
  59 +
  60 +        :param empty_cursor: A cursor coming from connectinos, it is necessary
  61 +       import the connections library from django.db, with it we can run
  62 +         sql commands.
  63 +
  64 +        :returns: Return is an revision object with your saved data
  65 +         in the colab database.
  66 +
  67 + """
41 revision = Revision() 68 revision = Revision()
42 cursor = self.revision_cursor(empty_cursor) 69 cursor = self.revision_cursor(empty_cursor)
43 revision_dict = self.dictfetchall(cursor) 70 revision_dict = self.dictfetchall(cursor)
@@ -52,6 +79,17 @@ class TracDataAPI(ProxyDataAPI): @@ -52,6 +79,17 @@ class TracDataAPI(ProxyDataAPI):
52 revision.repository_name = repository_dict[line['repos']] 79 revision.repository_name = repository_dict[line['repos']]
53 80
54 def fetch_data_ticket(self, empty_cursor): 81 def fetch_data_ticket(self, empty_cursor):
  82 + """ This method is responsible for seeking the ticket data in
  83 +        trac database and transfer them to the colab database.
  84 +
  85 +        :param empty_cursor: A cursor coming from connectinos, it is necessary
  86 +         import the connections library from django.db, with it we can run
  87 +         sql commands.
  88 +
  89 +        :returns: Return is an ticker object with your saved data
  90 +         in the colab database.
  91 +
  92 + """
55 ticket = Ticket() 93 ticket = Ticket()
56 collaborators = [] 94 collaborators = []
57 cursor = self.ticket_cursor(empty_cursor) 95 cursor = self.ticket_cursor(empty_cursor)
@@ -80,6 +118,17 @@ class TracDataAPI(ProxyDataAPI): @@ -80,6 +118,17 @@ class TracDataAPI(ProxyDataAPI):
80 ticket.collaborators = collaborators 118 ticket.collaborators = collaborators
81 119
82 def fetch_data_wiki(self, empty_cursor): 120 def fetch_data_wiki(self, empty_cursor):
  121 + """ This method is responsible for seeking the wiki data in
  122 +        trac database and transfer them to the colab database.
  123 +
  124 +        :param empty_cursor: A cursor coming from connectinos, it is necessary
  125 +         import the connections library from django.db, with it we can run
  126 +         sql commands.
  127 +
  128 +        :returns: Return is an wiki object with your saved data
  129 +         in the colab database.
  130 +
  131 + """
83 wiki = Wiki() 132 wiki = Wiki()
84 cursor = self.wiki_cursor(empty_cursor) 133 cursor = self.wiki_cursor(empty_cursor)
85 wiki_dict = self.dictfetchall(cursor) 134 wiki_dict = self.dictfetchall(cursor)
@@ -98,6 +147,19 @@ class TracDataAPI(ProxyDataAPI): @@ -98,6 +147,19 @@ class TracDataAPI(ProxyDataAPI):
98 wiki.save() 147 wiki.save()
99 148
100 def dictfetchall(self, cursor): 149 def dictfetchall(self, cursor):
  150 + """ This method is responsible for taking the cursor content
  151 +        and turn it into a dictionary.
  152 +
  153 +        The cursor returns an array of tuples, With this method it will return
  154 + a list of dictionaries..
  155 +
  156 +        :param cursor: A cursor coming from connections, it is necessary
  157 +         import the connections from library django.db, with it we can run
  158 +         sql commands.
  159 +
  160 +        :returns: Return are cursor.fetchall() in the format of dictionary
  161 +
  162 + """
101 desc = cursor.description 163 desc = cursor.description
102 return [ 164 return [
103 dict(zip([col[0] for col in desc], row)) 165 dict(zip([col[0] for col in desc], row))
@@ -105,26 +167,88 @@ class TracDataAPI(ProxyDataAPI): @@ -105,26 +167,88 @@ class TracDataAPI(ProxyDataAPI):
105 ] 167 ]
106 168
107 def wiki_cursor(self, cursor): 169 def wiki_cursor(self, cursor):
  170 + """ This is the method in charge of getting the wiki table data and
  171 +        put them in the cursor.
  172 +
  173 +        :param cursor: A cursor coming from connections, it is necessary
  174 +         import the connections from library django.db, with it we can run
  175 +         sql commands.
  176 +
  177 +        :returns: The return is the result of the desired query
  178 +
  179 + """
108 cursor.execute('''SELECT * FROM wiki;''') 180 cursor.execute('''SELECT * FROM wiki;''')
109 return cursor 181 return cursor
110 182
111 def attachment_cursor(self, cursor): 183 def attachment_cursor(self, cursor):
  184 + """ This is the method in charge of getting the attachment table data and
  185 +        put them in the cursor.
  186 +
  187 +        :param cursor: A cursor coming from connections, it is necessary
  188 +         import the connections from library django.db, with it we can run
  189 +         sql commands.
  190 +
  191 +        :returns: The return is the result of the desired query
  192 +
  193 + """
112 cursor.execute('''SELECT * FROM attachment;''') 194 cursor.execute('''SELECT * FROM attachment;''')
113 return cursor 195 return cursor
114 196
115 def ticket_cursor(self, cursor): 197 def ticket_cursor(self, cursor):
  198 + """ This is the method in charge of getting the ticket table data and
  199 +        put them in the cursor.
  200 +
  201 +        :param cursor: A cursor coming from connections, it is necessary
  202 +         import the connections from library django.db, with it we can run
  203 +         sql commands.
  204 +
  205 +        :returns: The return is the result of the desired query
  206 +
  207 + """
116 cursor.execute('''SELECT * FROM ticket;''') 208 cursor.execute('''SELECT * FROM ticket;''')
117 return cursor 209 return cursor
118 210
119 def revision_cursor(self, cursor): 211 def revision_cursor(self, cursor):
  212 + """ This is the method in charge of getting the revision table data and
  213 +        put them in the cursor.
  214 +
  215 +        :param cursor: A cursor coming from connections, it is necessary
  216 +         import the connections from library django.db, with it we can run
  217 +         sql commands.
  218 +
  219 +        :returns: The return is the result of the desired query
  220 +
  221 + """
120 cursor.execute('''SELECT * FROM revision;''') 222 cursor.execute('''SELECT * FROM revision;''')
121 return cursor 223 return cursor
122 224
123 def repository_cursor(self, cursor): 225 def repository_cursor(self, cursor):
  226 + """ This is the method in charge of getting the repository table data and
  227 +        put them in the cursor.
  228 +
  229 +        :param cursor: A cursor coming from connections, it is necessary
  230 +         import the connections from library django.db, with it we can run
  231 +         sql commands.
  232 +
  233 +        :returns: The return is the result of the desired query
  234 +
  235 + """
124 cursor.execute('''SELECT * FROM repository;''') 236 cursor.execute('''SELECT * FROM repository;''')
125 return cursor 237 return cursor
126 238
127 def get_wiki_modified(self, cursor, wiki_name): 239 def get_wiki_modified(self, cursor, wiki_name):
  240 + """ This is the method in charge of getting the datetime in the wiki was
  241 +        modified and put it in GMT format.
  242 +
  243 +        :param cursor: A cursor coming from connections, it is necessary
  244 +         import the connections from library django.db, with it we can run
  245 +         sql commands.
  246 +
  247 +        :param wiki_name: is the name of the current wiki.
  248 +
  249 +        :returns: The return is the result of the desired query
  250 +
  251 + """
128 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \ 252 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
129 (MAX(wiki.time)/1000000) * INTERVAL '1s', \ 253 (MAX(wiki.time)/1000000) * INTERVAL '1s', \
130 name from wiki where(name=\'""" + wiki_name + """\') \ 254 name from wiki where(name=\'""" + wiki_name + """\') \
@@ -134,6 +258,18 @@ class TracDataAPI(ProxyDataAPI): @@ -134,6 +258,18 @@ class TracDataAPI(ProxyDataAPI):
134 return modified_data 258 return modified_data
135 259
136 def get_wiki_created(self, cursor, wiki_name): 260 def get_wiki_created(self, cursor, wiki_name):
  261 + """ This is the method in charge of getting the datetime in the wiki was
  262 +        created and put it in GMT format.
  263 +
  264 +        :param cursor: A cursor coming from connections, it is necessary
  265 +         import the connections from library django.db, with it we can run
  266 +         sql commands.
  267 +
  268 +        :param wiki_name: is the name of the current wiki.
  269 +
  270 +        :returns: The return is the result of the desired query
  271 +
  272 + """
137 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \ 273 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
138 (MIN(wiki.time)/1000000) * INTERVAL '1s', \ 274 (MIN(wiki.time)/1000000) * INTERVAL '1s', \
139 name from wiki where(name=\'""" + wiki_name + """\') \ 275 name from wiki where(name=\'""" + wiki_name + """\') \
@@ -143,6 +279,18 @@ class TracDataAPI(ProxyDataAPI): @@ -143,6 +279,18 @@ class TracDataAPI(ProxyDataAPI):
143 return modified_data 279 return modified_data
144 280
145 def get_attachment_created(self, cursor, attachment_id): 281 def get_attachment_created(self, cursor, attachment_id):
  282 + """ This is the method in charge of getting the datetime in the
  283 + attachment was created and put it in GMT format.
  284 +
  285 +        :param cursor: A cursor coming from connections, it is necessary
  286 +         import the connections from library django.db, with it we can run
  287 +         sql commands.
  288 +
  289 +        :param attachment_id: is the id of the current attachment.
  290 +
  291 +        :returns: The return is the result of the desired query
  292 +
  293 + """
146 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \ 294 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
147 (MIN(attachment.time)/1000000) * INTERVAL '1s', \ 295 (MIN(attachment.time)/1000000) * INTERVAL '1s', \
148 id from attachment \ 296 id from attachment \
@@ -153,6 +301,18 @@ class TracDataAPI(ProxyDataAPI): @@ -153,6 +301,18 @@ class TracDataAPI(ProxyDataAPI):
153 return modified_data 301 return modified_data
154 302
155 def get_revision_created(self, cursor, revision): 303 def get_revision_created(self, cursor, revision):
  304 + """ This is the method in charge of getting the datetime in the revision
  305 + was modified and put it in GMT format.
  306 +
  307 +        :param cursor: A cursor coming from connections, it is necessary
  308 +         import the connections from library django.db, with it we can run
  309 +         sql commands.
  310 +
  311 +        :param revision: is the current revision.
  312 +
  313 +        :returns: The return is the result of the desired query
  314 +
  315 + """
156 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \ 316 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
157 (MIN(revision.time)/1000000) * INTERVAL '1s', \ 317 (MIN(revision.time)/1000000) * INTERVAL '1s', \
158 rev from revision where(rev=\'""" + revision + """\') \ 318 rev from revision where(rev=\'""" + revision + """\') \
@@ -162,6 +322,18 @@ class TracDataAPI(ProxyDataAPI): @@ -162,6 +322,18 @@ class TracDataAPI(ProxyDataAPI):
162 return modified_data 322 return modified_data
163 323
164 def get_ticket_created(self, cursor, ticket_id): 324 def get_ticket_created(self, cursor, ticket_id):
  325 + """ This is the method in charge of getting the datetime in the ticket
  326 + was created and put it in GMT format.
  327 +
  328 +        :param cursor: A cursor coming from connections, it is necessary
  329 +         import the connections from library django.db, with it we can run
  330 +         sql commands.
  331 +
  332 +        :param ticket_id: is the id of the current ticket.
  333 +
  334 +        :returns: The return is the result of the desired query
  335 +
  336 + """
165 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \ 337 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
166 (MIN(ticket.time)/1000000) * INTERVAL '1s', \ 338 (MIN(ticket.time)/1000000) * INTERVAL '1s', \
167 id from ticket where(id=""" + str(ticket_id) + """) \ 339 id from ticket where(id=""" + str(ticket_id) + """) \
@@ -171,6 +343,17 @@ class TracDataAPI(ProxyDataAPI): @@ -171,6 +343,17 @@ class TracDataAPI(ProxyDataAPI):
171 return modified_data 343 return modified_data
172 344
173 def get_ticket_modified(self, cursor, ticket_id): 345 def get_ticket_modified(self, cursor, ticket_id):
  346 + """ This is the method in charge of getting the datetime in the ticket
  347 + was modified and put it in GMT format.
  348 +
  349 +        :param cursor: A cursor coming from connections, it is necessary
  350 +         import the connections from library django.db, with it we can run
  351 +         sql commands.
  352 +
  353 +        :param ticket_id: is the id of the current ticket.
  354 +
  355 +        :returns: The return is the result of the desired query
  356 + """
174 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \ 357 cursor.execute("""SELECT TIMESTAMP WITH TIME ZONE 'epoch' + \
175 (MAX(ticket.time)/1000000) * INTERVAL '1s', \ 358 (MAX(ticket.time)/1000000) * INTERVAL '1s', \
176 id from ticket where(id=""" + str(ticket_id) + """) \ 359 id from ticket where(id=""" + str(ticket_id) + """) \
docs/source/conf.py
@@ -18,7 +18,9 @@ import os @@ -18,7 +18,9 @@ import os
18 # If extensions (or modules to document with autodoc) are in another directory, 18 # If extensions (or modules to document with autodoc) are in another directory,
19 # add these directories to sys.path here. If the directory is relative to the 19 # add these directories to sys.path here. If the directory is relative to the
20 # documentation root, use os.path.abspath to make it absolute, like shown here. 20 # documentation root, use os.path.abspath to make it absolute, like shown here.
21 -#sys.path.insert(0, os.path.abspath('.')) 21 +sys.path.insert(0, os.path.abspath('../../colab/proxy'))
  22 +from django.conf import settings
  23 +settings.configure()
22 24
23 # -- General configuration ------------------------------------------------ 25 # -- General configuration ------------------------------------------------
24 26
docs/source/dev.rst
1 Developer Documentation 1 Developer Documentation
2 -================== 2 +=======================
3 3
4 Getting Started 4 Getting Started
5 --------------- 5 ---------------
docs/source/index.rst
@@ -30,6 +30,8 @@ Contents: @@ -30,6 +30,8 @@ Contents:
30 user 30 user
31 plugindev 31 plugindev
32 dev 32 dev
  33 + trac
  34 +
33 35
34 36
35 Indices and tables 37 Indices and tables
@@ -38,4 +40,3 @@ Indices and tables @@ -38,4 +40,3 @@ Indices and tables
38 * :ref:`genindex` 40 * :ref:`genindex`
39 * :ref:`modindex` 41 * :ref:`modindex`
40 * :ref:`search` 42 * :ref:`search`
41 -  
docs/source/plugindev.rst
1 Plugin Developer Documentation 1 Plugin Developer Documentation
2 -================== 2 +==============================
3 3
4 Getting Started 4 Getting Started
5 --------------- 5 ---------------
docs/source/trac.rst 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +trac package
  2 +============
  3 +
  4 +Submodules
  5 +----------
  6 +
  7 +trac.data_api module
  8 +--------------------
  9 +
  10 +.. automodule:: trac.data_api
  11 + :members:
  12 + :undoc-members:
  13 + :show-inheritance:
docs/source/user.rst
@@ -16,6 +16,74 @@ Plugins @@ -16,6 +16,74 @@ Plugins
16 ------- 16 -------
17 .. TODO 17 .. TODO
18 18
  19 +Trac
  20 +++++
  21 +
  22 +
  23 +Dado que o Trac ja está instalado :
  24 +
  25 +- Vocẽ pode instalá-lo facilmente da seguinte maneira:
  26 +
  27 +.. code-block:: sh
  28 +
  29 + $ pip install trac
  30 +
  31 +Para ativar o plugin do Trac deve-se primeiramente configurar o banco de dados
  32 +do trac em:
  33 +
  34 +1. vim /etc/colab/settings.yml
  35 +
  36 +
  37 +.. code-block:: yaml
  38 +
  39 + DATABASES:
  40 + default:
  41 + ENGINE: django.db.backends.postgresql_psycopg2
  42 + HOST: localhost
  43 + NAME: colab
  44 + USER: colab
  45 + PASSWORD: colab
  46 + trac:
  47 + ENGINE: django.db.backends.postgresql_psycopg2
  48 + HOST: localhost
  49 + NAME: trac
  50 + USER: colab
  51 + PASSWORD: colab
  52 +
  53 +2. Ainda no mesmo arquivo descomentar o Trac em PROXIED_APPS
  54 +
  55 +.. code-block:: yaml
  56 +
  57 + PROXIED_APPS:
  58 + # gitlab:
  59 + # upstream: 'http://localhost:8090/gitlab/'
  60 + # private_token: ''
  61 + trac:
  62 + upstream: 'http://localhost:5000/trac/'
  63 +
  64 +3. Criar o banco de dados no postgresql com usuário colab
  65 +
  66 +.. code-block:: sh
  67 +
  68 + $ sudo -u postgres psql
  69 + $ create database trac owner colab;
  70 +
  71 +4. Agora você deve gerar as migrações do trac
  72 +
  73 +.. code-block:: sh
  74 +
  75 + # Dado que você está na pasta do colab
  76 + $ workon colab
  77 + $ colab-admin makemigrations trac
  78 + $ colab-admin migrate
  79 +
  80 +5. Por fim basta importar os dados do trac ( pode levar algumtempo ).
  81 +
  82 +.. code-block:: sh
  83 +
  84 + # Dado que você está na pasta do colab
  85 + $ colab-admin import_proxy_data
  86 +
19 Settings 87 Settings
20 -------- 88 --------
21 89