[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

mirrorman website_dummy.py,NONE,1.1 mm.py,1.2,1.3

Author: sopwith

Update of /cvs/fedora/mirrorman
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv5995

Modified Files:
Added Files:
Log Message:
Add dummy module for testing purposes

--- NEW FILE website_dummy.py ---
import pgdb
import sys
import Cookie
import os
import socket
import base64

rows_per_page = 25
domain = 'fedora.redhat.com'
accounts_email = 'accounts %s' % domain
dbname_map = {'auth':'fedorausers'}
dbcnx_map = {}

def print_header(title, auth_username=None, cache=0):
    print "Content-type: text/html"
    if not cache and 0:
        print "Cache-Control: no-cache, must-revalidate, no-store"
    window_title = title
    if auth_username:
        window_title += ' - Logged in as ' + auth_username
    print "<html><head><title>%s</title></head><body><h1>%s</h1>" % (window_title, title)

def print_footer(title, return_to=None):
    if return_to:
        print '<a href="%s">Return</a>' % return_to
    print "</body></html>"

class PostgresDBCursor:
    def __init__(self, dbc):
        self.dbc = dbc

    def __getattr__(self, key):
        return getattr(self.dbc, key)

    def fetchhash(self):
        dbr = self.dbc.fetchone()
        if not dbr:
            return None
        dbd = {}
        oldval = None
        descr = self.dbc.description
        for I in range(0, len(dbr)):
            dbd[descr[I][0]] = dbr[I]
        return dbd

class PostgresDBConnection:
    def __init__(self, *args, **kw):
        self.dbh = apply(pgdb.connect, args, kw)

    def __getattr__(self, key):
        return getattr(self.dbh, key)

    def cursor(self):
        return PostgresDBCursor(self.dbh.cursor())

def get_dbh(dbtype='auth', dbctx=None):
    if dbctx is None:
	hn = socket.gethostname()
	if hn.find('devel.redhat.com') >= 0:
		dbctx = 'devel'
		dbctx = 'live'
    dbname = dbname_map.get(dbtype, dbtype)
    dbcnx = dbcnx_map[dbctx]
    dbhost = dbcnx['host']
    dbuser = dbcnx['user']
    dbpass = dbcnx.get('password')
    return PostgresDBConnection(database=dbname, host=dbhost, user=dbuser, password=dbpass)

def set_auth(username='', password=''):

clear_auth = set_auth

def get_auth(dbh, form):
    return 'admin', 'admin'

def send_email(fromaddr, to, subject, body, cc=None):
    import email.Message, popen2
    msg = email.Message.Message()
    if not isinstance(to, tuple) and not isinstance(to, list):
        to = [to]
    msg.add_header('To', ', '.join(to))
    if cc:
        if not isinstance(cc, tuple) and not isinstance(cc, list):
            cc = [cc]
        msg.add_header('Cc', ', '.join(cc))
    msg.add_header('From', fromaddr)
    msg.add_header('Subject', subject)
    fh_read, fh_write = popen2.popen2("/usr/sbin/sendmail -t")

def do_error(title, message=None):
    if message:
        print "<hr>" + message

def handle_auth(auth_username, auth_password, form, url, title=None, require_auth=1):
    assert (auth_username and auth_password) or not require_auth
    return auth_username, auth_password

def have_group(dbh, username, group, require_role_type=None, require_role_domain=None, group_info=None):
    return 'administrator'

def get_allowed_group_actions(dbh, auth_username, groupname, group_info=None, for_username=None):
    allowed_actions = []
    allowed_actions.extend(['remove', 'approve', 'reject', 'sponsor', 'admin'])
    return allowed_actions

Index: mm.py
RCS file: /cvs/fedora/mirrorman/mm.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- mm.py	19 Nov 2004 21:19:28 -0000	1.2
+++ mm.py	7 Jun 2005 19:02:07 -0000	1.3
@@ -1,6 +1,9 @@
 import sys
-import website
+    import website
+    import website_dummy as website
 import urlparse, urllib2, mx.DateTime, md5, os
 def repo_editor(form, entity_id, dbh):

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]