Parent: [3abb2e] (diff)

Download this file

prweb_model.py    170 lines (145 with data), 5.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import logging
from pylons import c as context
from ming.utils import LazyProperty
from allura.lib import helpers as h
from .sfx_model import tables as T
log = logging.getLogger(__name__)
action_logger = h.log_action(log, 'SFX:')
class VHost(object):
def __init__(self, name):
self.name = name
@classmethod
def find(cls):
q = T.prweb_vhost.select()
q = q.where(
T.prweb_vhost.c.group_id==context.project.get_tool_data('sfx', 'group_id'))
for row in q.execute():
obj = cls(row['vhost_name'])
obj._row = row
yield obj
@classmethod
def get(cls, vhostid):
q = T.prweb_vhost.select()
q = q.where(
T.prweb_vhost.c.group_id==context.project.get_tool_data('sfx', 'group_id'))
q = q.where(
T.prweb_vhost.c.vhostid==vhostid)
row = q.execute().fetchone()
result = cls(row['vhost_name'])
result._row = row
return result
@classmethod
def create(cls, name):
action_logger.info('CreateVHOST')
stmt = T.prweb_vhost.insert()
homedir = '/home/groups/%s/' % (
h.sharded_path(context.project.get_tool_data('sfx', 'unix_group_name')))
docdir = homedir + 'htdocs/'
cgidir = homedir + 'cgi-bin/'
group_id = context.project.get_tool_data('sfx', 'group_id')
stmt.execute(
vhost_name=name,
docdir=docdir,
cgidir=cgidir,
group_id=group_id)
return cls(name)
def delete(self):
action_logger.info('DelVHOST')
stmt = T.prweb_vhost.delete()
stmt = stmt.where(
T.prweb_vhost.c.group_id==context.project.get_tool_data('sfx', 'group_id'))
stmt = stmt.where(
T.prweb_vhost.c.vhostid==self.vhostid)
stmt.execute()
@LazyProperty
def _row(self):
q = T.prweb_vhost.select(T.prweb_vhost.c.vhostid==self.name)
q = q.where(
T.prweb_vhost.c.group_id==context.project.get_tool_data('sfx', 'group_id'))
return q.execute().first()
def __getattr__(self, name):
try:
return self._row[name]
except KeyError:
raise AttributeError, name
class MySQL(object):
@classmethod
def create(cls, passwd_rouser, passwd_rwuser, passwd_adminuser):
action_logger.info('CreateMySQL')
stmt = T._mysql_auth.insert()
stmt.execute(
passwd_rouser=passwd_rouser,
passwd_rwuser=passwd_rwuser,
passwd_adminuser=passwd_adminuser,
modified_by_uid=context.user.get_tool_data('sfx', 'userid'),
group_id=context.project.get_tool_data('sfx', 'group_id'))
return cls()
@classmethod
def update(cls, passwd_rouser, passwd_rwuser, passwd_adminuser):
action_logger.info('UpdateMySQL')
group_id=context.project.get_tool_data('sfx', 'group_id')
stmt = T._mysql_auth.update(
whereclause=T._mysql_auth.c.group_id==group_id)
stmt.execute(
passwd_rouser=passwd_rouser,
passwd_rwuser=passwd_rwuser,
passwd_adminuser=passwd_adminuser,
modified_by_uid=context.user.get_tool_data('sfx', 'userid'))
@property
def prefix(self):
gid = context.project.get_tool_data('sfx', 'group_id')
name = str(context.project.get_tool_data('sfx', 'unix_group_name'))
return name[0] + str(gid)
@property
def hostname(self):
name = str(context.project.get_tool_data('sfx', 'unix_group_name'))
return 'mysql-' + name[0]
@property
def url(self):
return 'https://%s.sourceforge.net' % self.hostname
@LazyProperty
def _row(self):
q = T.mysql_auth.select()
q = q.where(
T.mysql_auth.c.group_id==context.project.get_tool_data('sfx', 'group_id'))
return q.execute().first()
def __getattr__(self, name):
if name == '_row':
raise AttributeError, name
elif self._row is None:
return None
try:
return self._row[name]
except KeyError:
raise AttributeError, name
class PRWebEmailAddress(object):
@classmethod
def create(cls, passwd=None):
action_logger.info('Create PRWebEmailAddress')
stmt = T._prweb_email.insert()
stmt.execute(
passwd=passwd,
modified_by_uid=context.user.get_tool_data('sfx', 'userid'),
group_id=context.project.get_tool_data('sfx', 'group_id'))
def update(self, passwd=None):
action_logger.info('Update PRWebEmailAddress')
stmt = T._prweb_email.update(
whereclause=T._prweb_email.c.group_id==self.group_id)
stmt.execute(
passwd=passwd,
modified_by_uid=context.user.get_tool_data('sfx', 'userid'))
@LazyProperty
def _row(self):
q = T.prweb_email.select()
q = q.where(
T.prweb_email.c.group_id==context.project.get_tool_data('sfx', 'group_id'))
return q.execute().first()
def __getattr__(self, name):
if name == '_row':
raise AttributeError, name
elif self._row is None:
return None
try:
return self._row[name]
except KeyError:
raise AttributeError, name