Commit deacd16b97ffff3f49f6a30d01e1157822e6d8b0

Authored by root
1 parent 1b24ecdc
Exists in master

alterações do wsc

wscacicneo/__init__.py
... ... @@ -12,7 +12,6 @@ from pyramid.httpexceptions import HTTPNotFound
12 12 def main(global_config, **settings):
13 13 """ This function returns a Pyramid WSGI application.
14 14 """
15   -
16 15 config.setup(settings)
17 16 from wscacicneo.security import groupfinder
18 17 authn_policy = AuthTktAuthenticationPolicy(
... ...
wscacicneo/config/__init__.py
1   -import os
2   -import configparser
  1 +#import os
  2 +#import configparser
3 3  
4 4 def setup(settings):
5 5  
... ...
wscacicneo/model/__init__.py 0 → 100644
No preview for this file type
wscacicneo/models.py
1   -from sqlalchemy import *
2   -from sqlalchemy.ext.declarative import declarative_base
3   -
4   -from pyramid.config import Configurator
5   -from pyramid_restler.model import SQLAlchemyORMContext
6   -
7   -from sqlalchemy.orm import (
8   - scoped_session,
9   - sessionmaker,
10   - mapper
11   - )
12   -
13   -from zope.sqlalchemy import ZopeTransactionExtension
14   -
15 1 from pyramid.security import (
16 2 Allow,
17 3 Everyone,
18 4 )
19 5  
20   -DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
21   -Base = declarative_base()
22   -
23   -class SistemaOperacional():
24   - """
25   - Classe que define os sistemas operacionais
26   -
27   - """
28   - __tablename__ = 'so'
29   -
30   - id_so = Column(Integer, primary_key=True)
31   - te_desc_so = Column(UnicodeText, nullable=True)
32   - sg_so = Column(UnicodeText, nullable=True)
33   - te_so = Column(UnicodeText, nullable=False)
34   - in_mswindows = Column(UnicodeText, default='S')
35   -
36   - def __init__ (self, id_so, te_desc_so, sg_so, te_so, in_mswindows):
37   - """
38   - Metodo que chama as colunas
39   - """
40   - self.id_so = id_so
41   - self.te_desc_so = te_desc_so
42   - self.sg_so = sg_so
43   - self.te_so = te_so
44   - self.in_mswindows = in_mswindows
45   -
46   - def __repr__(self):
47   - """
48   - Metodo que passa a lista de parametros da classe
49   - """
50   - return "<SistemaOperacional('%s, %s, %s, %s, %s')>" % (self.id_so, self.te_desc_so, self.sg_so, self.te_so, self.in_mswindows)
51   -class SistemaOperacionalContextFactory(SQLAlchemyORMContext):
52   - entity = SistemaOperacional
53   - def session_factory(self):
54   - return Session()
55   -
56   -
57   -so = Table('so', Base.metadata,
58   - Column('id_so', Integer, primary_key=True),
59   - Column('te_desc_so', UnicodeText, nullable=True),
60   - Column('sg_so', UnicodeText, nullable=True),
61   - Column('te_so', UnicodeText, nullable=False),
62   - Column('in_mswindows', UnicodeText, default='S')
63   - )
64   -
65   -mapper(SistemaOperacional, so)
66   -
67 6 class RootFactory(object):
68 7 __acl__ = [ (Allow, Everyone, 'user'),
69 8 (Allow, 'Administrador', 'admin') ]
70 9 def __init__(self, request):
71   - pass
72 10 \ No newline at end of file
  11 + pass
... ...
wscacicneo/monitor.py
... ... @@ -1,113 +0,0 @@
1   -import os
2   -import sys
3   -import time
4   -import signal
5   -import threading
6   -import atexit
7   -import queue as Queue
8   -
9   -_interval = 1.0
10   -_times = {}
11   -_files = []
12   -
13   -_running = False
14   -_queue = Queue.Queue()
15   -_lock = threading.Lock()
16   -
17   -def _restart(path):
18   - _queue.put(True)
19   - prefix = 'monitor (pid=%d):' % os.getpid()
20   - print >> sys.stderr, '%s Change detected to \'%s\'.' % (prefix, path)
21   - print >> sys.stderr, '%s Triggering process restart.' % prefix
22   - os.kill(os.getpid(), signal.SIGINT)
23   -
24   -def _modified(path):
25   - try:
26   - # If path doesn't denote a file and were previously
27   - # tracking it, then it has been removed or the file type
28   - # has changed so force a restart. If not previously
29   - # tracking the file then we can ignore it as probably
30   - # pseudo reference such as when file extracted from a
31   - # collection of modules contained in a zip file.
32   -
33   - if not os.path.isfile(path):
34   - return path in _times
35   -
36   - # Check for when file last modified.
37   -
38   - mtime = os.stat(path).st_mtime
39   - if path not in _times:
40   - _times[path] = mtime
41   -
42   - # Force restart when modification time has changed, even
43   - # if time now older, as that could indicate older file
44   - # has been restored.
45   -
46   - if mtime != _times[path]:
47   - return True
48   - except:
49   - # If any exception occured, likely that file has been
50   - # been removed just before stat(), so force a restart.
51   -
52   - return True
53   -
54   - return False
55   -
56   -def _monitor():
57   - while 1:
58   - # Check modification times on all files in sys.modules.
59   -
60   - for module in sys.modules.values():
61   - if not hasattr(module, '__file__'):
62   - continue
63   - path = getattr(module, '__file__')
64   - if not path:
65   - continue
66   - if os.path.splitext(path)[1] in ['.pyc', '.pyo', '.pyd']:
67   - path = path[:-1]
68   - if _modified(path):
69   - return _restart(path)
70   -
71   - # Check modification times on files which have
72   - # specifically been registered for monitoring.
73   -
74   - for path in _files:
75   - if _modified(path):
76   - return _restart(path)
77   -
78   - # Go to sleep for specified interval.
79   -
80   - try:
81   - return _queue.get(timeout=_interval)
82   - except:
83   - pass
84   -
85   -_thread = threading.Thread(target=_monitor)
86   -_thread.setDaemon(True)
87   -
88   -def _exiting():
89   - try:
90   - _queue.put(True)
91   - except:
92   - pass
93   - _thread.join()
94   -
95   -atexit.register(_exiting)
96   -
97   -def track(path):
98   - if not path in _files:
99   - _files.append(path)
100   -
101   -def start(interval=1.0):
102   - global _interval
103   - if interval < _interval:
104   - _interval = interval
105   -
106   - global _running
107   - _lock.acquire()
108   - if not _running:
109   - prefix = 'monitor (pid=%d):' % os.getpid()
110   - print >> sys.stderr, '%s Starting change monitor.' % prefix
111   - _running = True
112   - _thread.start()
113   - _lock.release()
wscacicneo/security.py
  1 +#!/usr/env python
  2 +# -*- coding: utf-8 -*-
1 3 # # 1. carregar usuário da sessão
2 4 # # 2. carregar objeto usuário
3 5 # # 3. pegar grupo do usuário
... ... @@ -20,4 +22,4 @@ def groupfinder(userid, request):
20 22 )
21 23 usuario = user_obj.search_user_by_email(userid)
22 24 permissao = usuario.results[0].permissao
23   - return [permissao]
24 25 \ No newline at end of file
  26 + return [permissao]
... ...
wscacicneo/utils/utils.py
  1 +#!/usr/env python
  2 +# -*- coding: utf-8 -*-
1 3 import requests
2 4 import json
3 5 import unicodedata
... ... @@ -24,4 +26,4 @@ class Utils:
24 26 # Retorna uma string sem caracteres especiais(sem espaço e acentos).
25 27 def format_name(data):
26 28 return ''.join(x for x in unicodedata.normalize('NFKD', data) if \
27   - unicodedata.category(x)[0] == 'L').lower()
28 29 \ No newline at end of file
  30 + unicodedata.category(x)[0] == 'L').lower()
... ...
wscacicneo/views.py
  1 +#!/usr/env python
  2 +# -*- coding: utf-8 -*-
1 3 import requests
2 4 import json
3 5 from pyramid.response import Response
4 6 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
5 7 from pyramid.view import view_config
6   -from sqlalchemy.orm import sessionmaker
7   -from sqlalchemy import create_engine, MetaData
8   -from .models import (
9   - DBSession,
10   - SistemaOperacional,
11   - )
12 8 from wscacicneo.utils.utils import Utils
13 9 from wscacicneo.model.orgao import Orgao
14 10 from wscacicneo.model.orgao import OrgaoBase
... ... @@ -30,11 +26,8 @@ from pyramid.security import (
30 26 forget,
31 27 )
32 28  
33   -engine = create_engine('postgresql://rest:rest@localhost/cacic')
34 29 REST_URL = 'http://api.brlight.net/api'
35 30  
36   -Session = sessionmaker(bind=engine)
37   -session = Session()
38 31  
39 32 # Views de configuração
40 33 @view_config(route_name='blankmaster', renderer='templates/blankmaster.pt')
... ...