Commit a18e9bd75f59bd089e34dfce80f3b111b6a169c6
1 parent
112cad2d
Exists in
master
and in
7 other branches
$1
Showing
5 changed files
with
253 additions
and
1 deletions
Show diff stats
admin/admin.db
No preview for this file type
admin/js/estat_editor.js
... | ... | @@ -533,7 +533,7 @@ i3GEOadmin.editor = { |
533 | 533 | '<option value=apagar >Apagar dados atuais e incluir do SHP</option>' + |
534 | 534 | '</select></p>' + |
535 | 535 | '<p class="paragrafo" >Código da projeção (SRID) Assegure-se que o shapefile esteja na projeção geográfica se você for usar com o sistema de metadados estatísticos :<br><input class=digitar type="text" value="4326" size=20 id="srid" name="srid" style="top:0px;left:0px;cursor:pointer;"></p>' + |
536 | - '<p class="paragrafo" ><input type="checkbox" id="incluiserialshp" name="incluiserialshp" style="cursor:pointer;position:relative;top:2px;"> Inclui uma coluna gid do tipo serial e chave primária com código único</p>' + | |
536 | + '<p class="paragrafo" ><input type="checkbox" id="incluiserialshp" name="incluiserialshp" style="cursor:pointer;position:relative;top:2px;"> Inclui uma coluna gid do tipo serial e chave primária com código único</p>' + | |
537 | 537 | '<p class="paragrafo" ><input id=i3GEOuploadsubmit type="button" value="Enviar" size=12 />' + |
538 | 538 | '<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' + |
539 | 539 | '<input type="hidden" id="i3GEOuploadcodigoconexao" name="i3GEOuploadcodigoconexao" value="">' + |
... | ... | @@ -564,6 +564,7 @@ i3GEOadmin.editor = { |
564 | 564 | $i("i3GEOuploadcodigoconexao").value = $i("i3GEOadmincodigo_estat_conexao").value; |
565 | 565 | $i("i3GEOuploadesquema").value = $i("i3GEOadminesquema").value; |
566 | 566 | $i("i3GEOuploadf").submit(); |
567 | + $i("tabelaDestino").value = ""; | |
567 | 568 | } |
568 | 569 | }, |
569 | 570 | uploadcsv: { |
... | ... | @@ -584,6 +585,8 @@ i3GEOadmin.editor = { |
584 | 585 | var ins = '<fieldset><form id=i3GEOuploadcsvf target="i3GEOuploadcsviframe" action="../php/metaestat_uploadcsv_submit.php" method="post" ENCTYPE="multipart/form-data">' + |
585 | 586 | '<p class="paragrafo" >CSV (utilize ponto como separador de valores decimais ou a importação poderá não ocorrer): <br><input class=digitar type="file" size=22 name="i3GEOuploadcsv" style="top:0px;left:0px;cursor:pointer;"></p>' + |
586 | 587 | '<p class="paragrafo" >Nome da nova tabela (não utilize caracteres incompatíveis com o banco de dados, como -, acentos ou espaços em branco):<br><input class=digitar type="text" size=20 id="tabelaDestinocsv" name="tabelaDestinocsv" style="top:0px;left:0px;cursor:pointer;"></p>' + |
588 | + '<p class="paragrafo" ><input type="checkbox" id="incluiserialcsv" name="incluiserialcsv" style="cursor:pointer;position:relative;top:2px;"> Inclui uma coluna gid do tipo serial e chave primária com código único</p>' + | |
589 | + | |
587 | 590 | '<p class="paragrafo" ><input id=i3GEOuploadcsvsubmit type="button" value="Enviar" size=12 />' + |
588 | 591 | '<input type="hidden" name="MAX_FILE_SIZE" value="1000000">' + |
589 | 592 | '<input type="hidden" id="i3GEOuploadcsvcodigoconexao" name="i3GEOuploadcsvcodigoconexao" value="">' + |
... | ... | @@ -602,6 +605,7 @@ i3GEOadmin.editor = { |
602 | 605 | $i("i3GEOuploadcsvcodigoconexao").value = $i("i3GEOadmincodigo_estat_conexao").value; |
603 | 606 | $i("i3GEOuploadcsvesquema").value = $i("i3GEOadminesquema").value; |
604 | 607 | $i("i3GEOuploadcsvf").submit(); |
608 | + $i("tabelaDestinocsv").value = ""; | |
605 | 609 | } |
606 | 610 | }, |
607 | 611 | esvaziaFormsUpload: function(){ | ... | ... |
admin/php/metaestat_uploadcsv_submit.php
... | ... | @@ -162,6 +162,9 @@ if (ob_get_level() == 0) ob_start(); |
162 | 162 | ob_flush(); |
163 | 163 | flush(); |
164 | 164 | sleep(1); |
165 | + if($_POST["incluiserialcsv"] == "on"){ | |
166 | + $linhasql[] = "alter table ".$_POST["i3GEOuploadcsvesquema"].".".$_POST["tabelaDestinocsv"]." add gid serial CONSTRAINT gid_pkey PRIMARY KEY"; | |
167 | + } | |
165 | 168 | foreach($sqltabela as $linha){ |
166 | 169 | try { |
167 | 170 | $dbh->query($linha); | ... | ... |
... | ... | @@ -0,0 +1,245 @@ |
1 | +#!/usr/bin/env python | |
2 | +# -*- coding: utf-8 -*- | |
3 | +""" | |
4 | +Created on Fri Jan 11 17:26:01 2013 | |
5 | + | |
6 | +@author: Diego | |
7 | +""" | |
8 | +import os, subprocess | |
9 | +import sqlite3 | |
10 | +import os | |
11 | +import time | |
12 | + | |
13 | +TABELA_ORIGINAL = 'tb_proxy' | |
14 | + | |
15 | +tables = {} | |
16 | +tables[TABELA_ORIGINAL] = [[u'id', u'INTEGER PRIMARY KEY'], | |
17 | + [u'proxy', u'TEXT'], | |
18 | + [u'port', u'TEXT'], | |
19 | + [u'user', u'TEXT'], | |
20 | + [u'password', u'TEXT'], | |
21 | + [u'exceptions', u'TEXT']] | |
22 | + | |
23 | +class ProxyDB(): | |
24 | + def __init__(self, path, nome): | |
25 | + self.con = self.getDB(path, nome) | |
26 | + if not self.isMetadadosDB(): | |
27 | + self.createTables() | |
28 | + | |
29 | + def getDB(self, path, nome): | |
30 | + banco = os.path.join(path,nome) | |
31 | + if os.path.exists(path): | |
32 | + try: | |
33 | + con = sqlite3.connect(banco) | |
34 | + return con | |
35 | + except: | |
36 | + print 'Não foi possível criar uma conecção com o BD:{0}'\ | |
37 | + .format(banco) | |
38 | + return None | |
39 | + else: | |
40 | + print 'Não foi possível encontrar o caminho especificado:{0}'\ | |
41 | + .format(banco) | |
42 | + return None | |
43 | + | |
44 | + | |
45 | + def isMetadadosDB(self): | |
46 | + cur = self.con.cursor() | |
47 | + tablesNames = tables.keys() | |
48 | + for i in tablesNames: | |
49 | + teste = False | |
50 | + for j in cur.execute("select name from sqlite_master where type ='table'"): | |
51 | + teste = i == j[0] | |
52 | + if teste: | |
53 | + break | |
54 | + if not teste: | |
55 | + return teste | |
56 | + return teste | |
57 | + | |
58 | + def createTables(self): | |
59 | + tablesName = tables.keys() | |
60 | + tablesName.reverse() | |
61 | + for table in tablesName : | |
62 | + sql = "CREATE TABLE {0}(".format(table) | |
63 | + columns = tables.get(table) | |
64 | + column = columns.pop(0) | |
65 | + sql = "{0} {1} {2}".format(sql, column[0], column[1]) | |
66 | + for column in columns: | |
67 | + sql = "{0}, {1} {2}".format(sql, column[0], column[1]) | |
68 | + sql = "{0});".format(sql) | |
69 | + cur = self.con.cursor() | |
70 | + cur.execute(sql) | |
71 | + self.con.commit() | |
72 | + | |
73 | + def inserirItem(self, nomeTabela, dicionario): | |
74 | + sql = "INSERT INTO {0}".format(nomeTabela) | |
75 | + columns = dicionario.keys() | |
76 | + values = [] | |
77 | + for key in columns: | |
78 | + value = dicionario.get(key) | |
79 | + if type(value) == str: | |
80 | + values.append("'{0}'".format(value)) | |
81 | + else: | |
82 | + values.append(str(value)) | |
83 | + | |
84 | + sql = '{0} {1} VALUES {2}'.format(sql, str(columns).replace("'", ''), \ | |
85 | + str(values).replace('"', '')).replace('[','(').replace(']',')') | |
86 | + cur = self.con.cursor() | |
87 | + cur.execute(sql) | |
88 | + self.con.commit() | |
89 | + | |
90 | + def obterProxyList(self): | |
91 | + cur = self.con.cursor() | |
92 | + proxyDict = {} | |
93 | + for e in cur.execute("SELECT id, proxy, port, user, password, exceptions FROM tb_proxy"): | |
94 | + proxyDict[e[0]] = {'proxy':e[1], 'port':e[2], 'user':e[3], 'password':e[4], 'exceptions':e[5] } | |
95 | + return proxyDict | |
96 | + | |
97 | + | |
98 | + def save(self): | |
99 | + self.con.commit() | |
100 | + | |
101 | + def close(self): | |
102 | + self.con.close() | |
103 | + | |
104 | +PROJECT_ROOT_PATH = os.path.realpath(os.path.dirname(__file__)) | |
105 | +metadadosDB = ProxyDB(PROJECT_ROOT_PATH, 'proxy.db') | |
106 | + | |
107 | +def validaEntradaSN(msg): | |
108 | + while True: | |
109 | + var = raw_input(msg) | |
110 | + if var.upper() == 'S': | |
111 | + return True | |
112 | + elif var.upper() == 'N': | |
113 | + return False | |
114 | + | |
115 | +def validaEntradaTexto(msg): | |
116 | + while True: | |
117 | + var = raw_input(msg) | |
118 | + if len(var) > 0: | |
119 | + return var | |
120 | + | |
121 | +def validaEntradaNumero(msg): | |
122 | + while True: | |
123 | + var = raw_input(msg) | |
124 | + if len(var) > 0: | |
125 | + try: | |
126 | + int(var) | |
127 | + return var | |
128 | + except: | |
129 | + print 'O valor deve ser do tipo interio!' | |
130 | + return None | |
131 | + | |
132 | +def insertProxy(): | |
133 | + continua = True | |
134 | + proxyDict = {} | |
135 | + while continua : | |
136 | + proxyDict['proxy'] = validaEntradaTexto("Informe o proxy: ") | |
137 | + proxyDict['port'] = validaEntradaNumero("Informe a porta: ") | |
138 | + if validaEntradaSN("Seu proxy requer autenticação? (S ou N)\n>> "): | |
139 | + proxyDict['user'] = validaEntradaTexto("Informe o usuário: ") | |
140 | + proxyDict['password'] = validaEntradaTexto("Informe a senha: ") | |
141 | + if validaEntradaSN("Você quer cadastrar exceções? (S ou N)\n>> "): | |
142 | + proxyDict['exceptions'] = validaEntradaTexto("Informe as exceções: ") | |
143 | + | |
144 | + for i in proxyDict: | |
145 | + print i, '\t- ', proxyDict[i] | |
146 | + | |
147 | + msg = "Esta é a configurção de proxy que será utilizada:\nEla está correta? (S ou N)\n>>" | |
148 | + if validaEntradaSN(msg): | |
149 | + continua = False | |
150 | + metadadosDB.inserirItem(TABELA_ORIGINAL, proxyDict) | |
151 | + '''serversPath = os.path.join(PROJECT_ROOT_PATH,'.subversion/servers') | |
152 | + serversFile = open(serversPath,'a+b') | |
153 | + serversFile.write("http-proxy-host = {0}\n".format(proxy)) | |
154 | + serversFile.write("http-proxy-port = {0}\n".format(porta)) | |
155 | + if usuario: | |
156 | + serversFile.write("http-proxy-username = {0}\n".format(usuario)) | |
157 | + serversFile.write("http-proxy-password = {0}\n".format(senha)) | |
158 | + serversFile.close() | |
159 | + atualiza_info_file = open(atualizaPath,'w') | |
160 | + atualiza_info_file.close()''' | |
161 | + | |
162 | + else: | |
163 | + for i in proxyDict.keys(): | |
164 | + proxyDict[i] = '' | |
165 | + return proxyDict | |
166 | + | |
167 | +def utilizarProxy(proxyDict): | |
168 | + serversPath = os.path.join(PROJECT_ROOT_PATH,'.subversion/servers') | |
169 | + serversFile = open(serversPath,'w') | |
170 | + serversFile.write("[global]\n") | |
171 | + | |
172 | + fileDict = {'proxy': 'http-proxy-host = ', | |
173 | + 'port':'http-proxy-port = ', | |
174 | + 'user': 'http-proxy-username = ', | |
175 | + 'password':'http-proxy-username = ', | |
176 | + 'exceptions':'http-proxy-password = '} | |
177 | + if proxyDict: | |
178 | + for k,v in proxyDict.items(): | |
179 | + if v: | |
180 | + serversFile.write(fileDict[k] + v + '\n') | |
181 | + serversFile.close() | |
182 | + atualiza() | |
183 | + | |
184 | + | |
185 | +def proxy(): | |
186 | + | |
187 | + texto = "Se você utiliza um proxy para acessar a web é necessário que o proxy seja configurado para fazer o update.\ | |
188 | + Caso você configure o proxy e o update não seja executado com sucesso, procure o seu administrador da rede e informe a ele o seguinte:\n\ | |
189 | + 1 - Arquivo local que armazena as configurações do proxy para o svn: {0}\n\ | |
190 | + 2 - É preciso que o servidor proxy suporte os seguintes métodos: PROPFIND, REPORT, MERGE, MKACTIVITY, CHECKOUT.\n\ | |
191 | + 3 - Mais informações: http://subversion.apache.org/faq.html#proxy\n\n".format(os.path.join(PROJECT_ROOT_PATH,'.subversion/servers')) | |
192 | + | |
193 | + print texto | |
194 | + | |
195 | + | |
196 | + a = metadadosDB.obterProxyList() | |
197 | + print 'Escolha o que fazer:' | |
198 | + print '-1 - para restaurar as configurações iniciais;' | |
199 | + print ' 0 - para cadastrar um proxy novo;' | |
200 | + print ' Ou Digite o numero de um proxy cadastrado, caso exista.\n' | |
201 | + | |
202 | + if len(a): | |
203 | + print 'Proxies disponíveis:' | |
204 | + for i in a: | |
205 | + print i,' - ', a[i]['proxy'],a[i]['port'],a[i]['user'],a[i]['password'],a[i]['exceptions'] | |
206 | + metadadosDB.close() | |
207 | + | |
208 | + var = int(validaEntradaNumero(">>")) | |
209 | + | |
210 | + proxyDict = None | |
211 | + if var == 0: | |
212 | + proxyDict = insertProxy() | |
213 | + | |
214 | + elif var == -1: | |
215 | + proxyDict = None | |
216 | + else: | |
217 | + if var in a: | |
218 | + proxyDict = a[var] | |
219 | + else: | |
220 | + print 'Opção inválida!' | |
221 | + return | |
222 | + utilizarProxy(proxyDict) | |
223 | + | |
224 | +def atualiza(): | |
225 | + os.chdir('/var/www') | |
226 | + subprocess.call(["svn","update"], stdout=0) | |
227 | + | |
228 | +if __name__ == '__main__': | |
229 | + continua = True | |
230 | + while continua : | |
231 | + print 'Opções:' | |
232 | + print '0 - Atualizar:' | |
233 | + print '1 - Configurar Proxy e Atualizar:' | |
234 | + print '2 - Sair:' | |
235 | + var = int(validaEntradaNumero("Escolha: ")) | |
236 | + if var == 0: | |
237 | + atualiza() | |
238 | + elif var == 1: | |
239 | + proxy() | |
240 | + elif var == 2: | |
241 | + continua = False | |
242 | + | |
243 | + continua = False | |
244 | + time.sleep(5) | |
245 | + | ... | ... |
No preview for this file type