rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
print 'list'
def list(self, sort=None, group=None, filter=None, columns=None, filterspec=None, show_customization=None, show_nodes=1, pagesize=None): ''' call the template index with the args
print `props`
def _createnode(self): ''' create a node based on the contents of the form ''' cl = self.db.classes[self.classname] props = parsePropsFromForm(self.db, cl, self.form)
def _createnode(self): ''' create a node based on the contents of the form ''' cl = self.db.classes[self.classname] props, dummy = parsePropsFromForm(self.db, cl, self.form) if not props.has_key('status'): try: unread_id = self.db.status.lookup('unread') except KeyError: pass else: props['status'] = unread_id if props.has_key('assignedto'): assignedto_id = props['assignedto'] if props.has_key('nosy') and not assignedto_id in props['nosy']: props['nosy'].append(assignedto_id) else: props['nosy'] = [assignedto_id] message = self._handle_message() if message: props['messages'] = [message] return cl.create(**props) def _changenode(self, props): ''' change the node based on the contents of the form ''' cl = self.db.classes[self.classname] try: unread_id = self.db.status.lookup('unread') resolved_id = self.db.status.lookup('resolved') chatting_id = self.db.status.lookup('chatting') except KeyError: pass else: if (props['status'] == unread_id or props['status'] == resolved_id): props['status'] = chatting_id if props.has_key('assignedto'): assignedto_id = props['assignedto'] if not assignedto_id in props['nosy']: props['nosy'].append(assignedto_id) message = self._handle_message() if message: props['messages'] = cl.get(self.nodeid, 'messages') + [message] cl.set(self.nodeid, **props) def _handle_message(self): ''' generate and edit message ''' files = [] if self.form.has_key('__file'): file = self.form['__file'] if file.filename: mime_type = mimetypes.guess_type(file.filename)[0] if not mime_type: mime_type = "application/octet-stream" files.append(self.db.file.create(type=mime_type, name=file.filename, content=file.file.read())) cn = self.classname cl = self.db.classes[self.classname] props = cl.getprops() note = None if self.form.has_key('__note'): note = self.form['__note'].value if not props.has_key('messages'): return if not isinstance(props['messages'], hyperdb.Multilink): return if not props['messages'].classname == 'msg': return if not (self.form.has_key('nosy') or note): return if note: if '\n' in note: summary = re.split(r'\n\r?', note)[0] else: summary = note m = ['%s\n'%note] else: summary = _('This %(classname)s has been edited through' ' the web.\n')%{'classname': cn} m = [summary] content = '\n'.join(m) message_id = self.db.msg.create(author=self.getuid(), recipients=[], date=date.Date('.'), summary=summary, content=content, files=files) return message_id def _post_editnode(self, nid): ''' do the linking part of the node creation ''' cn = self.classname cl = self.db.classes[cn] keys = self.form.keys() for key in keys: if key == ':multilink': value = self.form[key].value if type(value) != type([]): value = [value] for value in value: designator, property = value.split(':') link, nodeid = roundupdb.splitDesignator(designator) link = self.db.classes[link] value = link.get(nodeid, property) value.append(nid) link.set(nodeid, **{property: value}) elif key == ':link': value = self.form[key].value if type(value) != type([]): value = [value] for value in value: designator, property = value.split(':') link, nodeid = roundupdb.splitDesignator(designator) link = self.db.classes[link] link.set(nodeid, **{property: nid}) def newnode(self, message=None): ''' Add a new node to the database. The form works in two modes: blank form and submission (that is, the submission goes to the same URL). **Eventually this means that the form will have previously entered information in it if submission fails. The new node will be created with the properties specified in the form submission. For multilinks, multiple form entries are handled, as are prop=value,value,value. You can't mix them though. If the new node is to be referenced from somewhere else immediately (ie. the new node is a file that is to be attached to a support issue) then supply one of these arguments in addition to the usual form entries: :link=designator:property :multilink=designator:property ... which means that once the new node is created, the "property" on the node given by "designator" should now reference the new node's id. The node id will be appended to the multilink. ''' cn = self.classname cl = self.db.classes[cn] keys = self.form.keys() if [i for i in keys if i[0] != ':']: props = {} try: nid = self._createnode() self._post_editnode(nid) message = _('%(classname)s created ok')%{'classname': cn} except: self.db.rollback() s = StringIO.StringIO() traceback.print_exc(None, s) message = '<pre>%s</pre>'%cgi.escape(s.getvalue()) self.pagehead(_('New %(classname)s')%{'classname': self.classname.capitalize()}, message) newitem = htmltemplate.NewItemTemplate(self, self.TEMPLATES, self.classname) newitem.render(self.form) self.pagefoot() newissue = newnode newuser = newnode def newfile(self, message=None): ''' Add a new file to the database. This form works very much the same way as newnode - it just has a file upload. ''' cn = self.classname cl = self.db.classes[cn] keys = self.form.keys() if [i for i in keys if i[0] != ':']: try: file = self.form['content'] mime_type = mimetypes.guess_type(file.filename)[0] if not mime_type: mime_type = "application/octet-stream" nid = cl.create(content=file.file.read(), type=mime_type, name=file.filename) self._post_editnode(nid) message = _('%(classname)s created ok')%{'classname': cn} except: self.db.rollback() s = StringIO.StringIO() traceback.print_exc(None, s) message = '<pre>%s</pre>'%cgi.escape(s.getvalue()) self.pagehead(_('New %(classname)s')%{'classname': self.classname.capitalize()}, message) newitem = htmltemplate.NewItemTemplate(self, self.TEMPLATES, self.classname) newitem.render(self.form) self.pagefoot()
def showfile(self): ''' display a file ''' nodeid = self.nodeid cl = self.db.file mime_type = cl.get(nodeid, 'type') if mime_type == 'message/rfc822': mime_type = 'text/plain' self.header(headers={'Content-Type': mime_type}) self.write(cl.get(nodeid, 'content'))
if hasattr(backends, 'mysql'): l.append(unittest.makeSuite(mysqlDBTestCase, 'test')) l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test'))
p = []
def suite(): l = [ unittest.makeSuite(anydbmDBTestCase, 'test'), unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') ]
value = str(value)
if type(value) != type(''): raise ValueError, 'link value must be String'
def create(self, **propvalues): """Create a new node of this class and return its id.
raise ValueError, 'new property "%s": %s not a %s'%(
raise IndexError, 'new property "%s": %s not a %s'%(
def create(self, **propvalues): """Create a new node of this class and return its id.
raise ValueError, '%s has no node %s'%(link_class, value)
raise IndexError, '%s has no node %s'%(link_class, value)
def create(self, **propvalues): """Create a new node of this class and return its id.
for entry in map(str, value):
for entry in value: if type(entry) != type(''): raise ValueError, 'link value must be String'
def create(self, **propvalues): """Create a new node of this class and return its id.
raise ValueError, '%s has no node %s'%(link_class, id)
raise IndexError, '%s has no node %s'%(link_class, id)
def create(self, **propvalues): """Create a new node of this class and return its id.
for key,prop in self.properties.items(): if propvalues.has_key(str(key)):
for key, prop in self.properties.items(): if propvalues.has_key(key):
def create(self, **propvalues): """Create a new node of this class and return its id.
d = self.db.getnode(self.classname, str(nodeid))
d = self.db.getnode(self.classname, nodeid)
def get(self, nodeid, propname): """Get the value of a property on an existing node of this class.
nodeid = str(nodeid)
def set(self, nodeid, **propvalues): """Modify a property on an existing node of this class. 'nodeid' must be the id of an existing node of this class or an IndexError is raised.
value = str(value)
def set(self, nodeid, **propvalues): """Modify a property on an existing node of this class. 'nodeid' must be the id of an existing node of this class or an IndexError is raised.
raise ValueError, 'new property "%s": %s not a %s'%(
raise IndexError, 'new property "%s": %s not a %s'%(
def set(self, nodeid, **propvalues): """Modify a property on an existing node of this class. 'nodeid' must be the id of an existing node of this class or an IndexError is raised.
raise ValueError, '%s has no node %s'%(link_class, value)
raise IndexError, '%s has no node %s'%(link_class, value)
def set(self, nodeid, **propvalues): """Modify a property on an existing node of this class. 'nodeid' must be the id of an existing node of this class or an IndexError is raised.
for entry in map(str, value):
for entry in value: if type(entry) != type(''): raise ValueError, 'link value must be String'
def set(self, nodeid, **propvalues): """Modify a property on an existing node of this class. 'nodeid' must be the id of an existing node of this class or an IndexError is raised.
raise ValueError, '%s has no node %s'%(link_class, id)
raise IndexError, '%s has no node %s'%(link_class, id)
def set(self, nodeid, **propvalues): """Modify a property on an existing node of this class. 'nodeid' must be the id of an existing node of this class or an IndexError is raised.
nodeid = str(nodeid)
def retire(self, nodeid): """Retire a node. The properties on the node remain available from the get() method, and the node's id is never reused. Retired nodes are not returned by the find(), list(), or lookup() methods, and other nodes may reuse the values of their key properties. """ nodeid = str(nodeid) if self.db.journaltag is None: raise DatabaseError, 'Database open read-only' node = self.db.getnode(self.classname, nodeid) node[self.db.RETIRED_FLAG] = 1 self.db.setnode(self.classname, nodeid, node) self.db.addjournal(self.classname, nodeid, 'retired', None)
nodeid = str(nodeid)
def find(self, **propspec): """Get the ids of nodes in this class which link to a given node.
if msgid:
if msgid is not None:
def good_recipient(userid): # Make sure we don't send mail to either the anonymous # user or a user who has already seen the message. return (userid and (self.db.user.get(userid, 'username') != 'anonymous') and not seen_message.has_key(userid))
message_files = msgid and messages.get(msgid, 'files') or None
if msgid is None: message_files = None else: message_files = messages.get(msgid, 'files')
def send_message(self, nodeid, msgid, note, sendto, from_address=None, bcc_sendto=[]): '''Actually send the nominated message from this node to the sendto recipients, with the note appended. ''' users = self.db.user messages = self.db.msg files = self.db.file
errors = '\n- '.join(errors)
errors = '\n- '.join(map(str, errors))
def handle_message(self, message): ''' message - a Message instance
return '<a href="%s">%s%s</a>'%(s, s1, s2)
return '<a href="%s%s">%s</a>'%(s1, s2, s)
def _hyper_repl(self, match): if match.group('url'): s = match.group('url') return '<a href="%s">%s</a>'%(s, s) elif match.group('email'): s = match.group('email') return '<a href="mailto:%s">%s</a>'%(s, s) else: s = match.group('item') s1 = match.group('class').lower() s2 = match.group('id') try: # make sure s1 is a valid tracker classname cl = self._db.getclass(s1) if not cl.hasnode(s2): raise KeyError, 'oops' return '<a href="%s">%s%s</a>'%(s, s1, s2) except KeyError: return '%s%s'%(s1, s2)
return '%s%s'%(s1, s2)
return s
def _hyper_repl(self, match): if match.group('url'): s = match.group('url') return '<a href="%s">%s</a>'%(s, s) elif match.group('email'): s = match.group('email') return '<a href="mailto:%s">%s</a>'%(s, s) else: s = match.group('item') s1 = match.group('class').lower() s2 = match.group('id') try: # make sure s1 is a valid tracker classname cl = self._db.getclass(s1) if not cl.hasnode(s2): raise KeyError, 'oops' return '<a href="%s">%s%s</a>'%(s, s1, s2) except KeyError: return '%s%s'%(s1, s2)
s = ','.join([a for x in v]) where.append('(_%s in (%s)%s)'%(k, s, xtra)) args = args + v
if v: s = ','.join([a for x in v]) where.append('(_%s in (%s)%s)'%(k, s, xtra)) args = args + v else: where.append('_%s is NULL'%k)
def filter(self, search_matches, filterspec, sort=(None,None), group=(None,None)): ''' Return a list of the ids of the active nodes in this class that match the 'filter' spec, sorted by the group spec and then the sort spec
self.dispname = None
def _post_init(self): ''' Set attributes based on self.form ''' # extract the index display information from the form self.columns = [] for name in ':columns @columns'.split(): if self.form.has_key(name): self.special_char = name[0] self.columns = handleListCGIValue(self.form[name]) break self.show = support.TruthDict(self.columns)
value = self.form['@dispname'].value self.dispname = value.decode(self.client.charset)
self.dispname = self.form['@dispname'].value else: self.dispname = None
def _post_init(self): ''' Set attributes based on self.form ''' # extract the index display information from the form self.columns = [] for name in ':columns @columns'.split(): if self.form.has_key(name): self.special_char = name[0] self.columns = handleListCGIValue(self.form[name]) break self.show = support.TruthDict(self.columns)
raise Unauthorised, self._('You do not have permission to '
raise exceptions.Unauthorised, self._( 'You do not have permission to '
def permission(self): """Check whether the user has permission to execute this action.
raise SeriousError, self._('No ID entered')
raise exceptions.SeriousError, self._('No ID entered')
def handle(self, typere=re.compile('[@:]type'), numre=re.compile('[@:]number')): """Show a node of a particular class/id.""" t = n = '' for key in self.form.keys(): if typere.match(key): t = self.form[key].value.strip() elif numre.match(key): n = self.form[key].value.strip() if not t: raise ValueError, self._('No type specified') if not n: raise SeriousError, self._('No ID entered') try: int(n) except ValueError: d = {'input': n, 'classname': t} raise SeriousError, self._( '"%(input)s" is not an ID (%(classname)s ID required)')%d url = '%s%s%s'%(self.base, t, n) raise Redirect, url
raise SeriousError, self._(
raise exceptions.SeriousError, self._(
def handle(self, typere=re.compile('[@:]type'), numre=re.compile('[@:]number')): """Show a node of a particular class/id.""" t = n = '' for key in self.form.keys(): if typere.match(key): t = self.form[key].value.strip() elif numre.match(key): n = self.form[key].value.strip() if not t: raise ValueError, self._('No type specified') if not n: raise SeriousError, self._('No ID entered') try: int(n) except ValueError: d = {'input': n, 'classname': t} raise SeriousError, self._( '"%(input)s" is not an ID (%(classname)s ID required)')%d url = '%s%s%s'%(self.base, t, n) raise Redirect, url
raise Redirect, url
raise exceptions.Redirect, url
def handle(self, typere=re.compile('[@:]type'), numre=re.compile('[@:]number')): """Show a node of a particular class/id.""" t = n = '' for key in self.form.keys(): if typere.match(key): t = self.form[key].value.strip() elif numre.match(key): n = self.form[key].value.strip() if not t: raise ValueError, self._('No type specified') if not n: raise SeriousError, self._('No ID entered') try: int(n) except ValueError: d = {'input': n, 'classname': t} raise SeriousError, self._( '"%(input)s" is not an ID (%(classname)s ID required)')%d url = '%s%s%s'%(self.base, t, n) raise Redirect, url
raise Unauthorised, self._(
raise exceptions.Unauthorised, self._(
def _changenode(self, cn, nodeid, props): """Change the node based on the contents of the form.""" # check for permission if not self.editItemPermission(props): raise Unauthorised, self._( 'You do not have permission to edit %(class)s' ) % {'class': cn}
raise Unauthorised, self._(
raise exceptions.Unauthorised, self._(
def _createnode(self, cn, props): """Create a node based on the contents of the form.""" # check for permission if not self.newItemPermission(props): raise Unauthorised, self._( 'You do not have permission to create %(class)s' ) % {'class': cn}
raise Unauthorised, self._(
raise exceptions.Unauthorised, self._(
def editItemPermission(self, props): """Determine whether the user has permission to edit this item.
raise Redirect, url
raise exceptions.Redirect, url
def handle(self): """Perform an edit of an item in the database.
raise Redirect, '%s%s%s?@ok_message=%s&@template=%s'%(self.base, self.classname, self.nodeid, urllib.quote(messages),
raise exceptions.Redirect, '%s%s%s?@ok_message=%s&@template=%s' % ( self.base, self.classname, self.nodeid, urllib.quote(messages),
def handle(self): ''' Add a new item to the database.
raise Unauthorised, self._(
raise exceptions.Unauthorised, self._(
def handle(self): """Attempt to create a new user based on the contents of the form and then set the cookie.
raise Redirect, '%suser?@template=rego_progress'%self.base
raise exceptions.Redirect, '%suser?@template=rego_progress'%self.base
def handle(self): """Attempt to create a new user based on the contents of the form and then set the cookie.
self.client.userid = self.db.user.lookup(self.client.user)
self.client.userid = self.db.user.lookup(username)
def handle(self): """Attempt to log a user in.
name = self.client.user self.client.error_message.append(self._('Ivalid login')) self.client.make_user_anonymous() return
raise exceptions.LoginError, self._('Invalid login')
def handle(self): """Attempt to log a user in.
self.client.make_user_anonymous() self.client.error_message.append(self._('Invalid login')) return
raise exceptions.LoginError, self._('Invalid login')
def handle(self): """Attempt to log a user in.
self.client.make_user_anonymous() self.client.error_message.append( self._("You do not have permission to login")) return self.client.opendb(self.client.user) self.client.set_cookie(self.client.user)
raise exceptions.LoginError, self._( "You do not have permission to login")
def handle(self): """Attempt to log a user in.
for name in os.listdir(dirname): if not name.endswith('.py'): continue vars = {} self._load_python(os.path.join(dirname, name), vars) vars['init'](parent)
if os.path.isdir(dirname): for name in os.listdir(dirname): if not name.endswith('.py'): continue vars = {} self._load_python(os.path.join(dirname, name), vars) vars['init'](parent)
def load_extensions(self, parent, dirname): dirname = os.path.join(self.tracker_home, dirname) for name in os.listdir(dirname): if not name.endswith('.py'): continue vars = {} self._load_python(os.path.join(dirname, name), vars) vars['init'](parent)
def __init__(self, spec='.', offset=0, add_granularity=0):
def __init__(self, spec='.', offset=0, add_granularity=0, translator=i18n):
def __init__(self, spec='.', offset=0, add_granularity=0): """Construct a date given a specification and a time zone offset.
raise ValueError, _('Not a date spec: %s' % self.usagespec)
raise ValueError, self._('Not a date spec: %s') % self.usagespec
def set(self, spec, offset=0, date_re=re.compile(r''' ((?P<y>\d\d\d\d)([/-](?P<m>\d\d?)([/-](?P<d>\d\d?))?)? # yyyy[-mm[-dd]] |(?P<a>\d\d?)[/-](?P<b>\d\d?))? # or mm-dd (?P<n>\.)? # . (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d(\.\d+)?))?)? # hh:mm:ss (?P<o>.+)? # offset ''', re.VERBOSE), serialised_re=re.compile(r''' (\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d?(\.\d+)?) ''', re.VERBOSE), add_granularity=0): ''' set the date to the value in spec '''
raise ValueError, _('%r not a date spec (%s)')%(spec,
raise ValueError, self._('%r not a date spec (%s)')%(spec,
def set(self, spec, offset=0, date_re=re.compile(r''' ((?P<y>\d\d\d\d)([/-](?P<m>\d\d?)([/-](?P<d>\d\d?))?)? # yyyy[-mm[-dd]] |(?P<a>\d\d?)[/-](?P<b>\d\d?))? # or mm-dd (?P<n>\.)? # . (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d(\.\d+)?))?)? # hh:mm:ss (?P<o>.+)? # offset ''', re.VERBOSE), serialised_re=re.compile(r''' (\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d?(\.\d+)?) ''', re.VERBOSE), add_granularity=0): ''' set the date to the value in spec '''
def __init__(self, spec, sign=1, allowdate=1, add_granularity=0):
def __init__(self, spec, sign=1, allowdate=1, add_granularity=0, translator=i18n ):
def __init__(self, spec, sign=1, allowdate=1, add_granularity=0): """Construct an interval given a specification.""" if type(spec) in (IntType, FloatType, LongType): self.from_seconds(spec) elif type(spec) in (StringType, UnicodeType): self.set(spec, allowdate=allowdate, add_granularity=add_granularity) else: if len(spec) == 7: self.sign, self.year, self.month, self.day, self.hour, \ self.minute, self.second = spec self.second = int(self.second) else: # old, buggy spec form self.sign = sign self.year, self.month, self.day, self.hour, self.minute, \ self.second = spec self.second = int(self.second)
raise ValueError, _('Not an interval spec: [+-] [ '[
raise ValueError, self._('Not an interval spec:' ' [+-] [
def set(self, spec, allowdate=1, interval_re=re.compile(''' \s*(?P<s>[-+])? # + or - \s*((?P<y>\d+\s*)y)? # year \s*((?P<m>\d+\s*)m)? # month \s*((?P<w>\d+\s*)w)? # week \s*((?P<d>\d+\s*)d)? # day \s*(((?P<H>\d+):(?P<M>\d+))?(:(?P<S>\d+))?)? # time \s*(?P<D> (\d\d\d\d[/-])?(\d\d?)?[/-](\d\d?)? # [yyyy-]mm-dd \.? # . (\d?\d:\d\d)?(:\d\d)? # hh:mm:ss )?''', re.VERBOSE), serialised_re=re.compile(''' (?P<s>[+-])?1?(?P<y>([ ]{3}\d|\d{4}))(?P<m>\d{2})(?P<d>\d{2}) (?P<H>\d{2})(?P<M>\d{2})(?P<S>\d{2})''', re.VERBOSE), add_granularity=0): ''' set the date to the value in spec ''' self.year = self.month = self.week = self.day = self.hour = \ self.minute = self.second = 0 self.sign = 1 m = serialised_re.match(spec) if not m: m = interval_re.match(spec) if not m: raise ValueError, _('Not an interval spec: [+-] [#y] [#m] [#w] ' '[#d] [[[H]H:MM]:SS] [date spec]') else: allowdate = 0
if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)}
s = self.ngettext("%(number)s year", "%(number)s years", self.year) % {'number': self.year} elif self.month or self.day > 28: _months = int(((self.month * 30) + self.day) / 30) s = self.ngettext("%(number)s month", "%(number)s months", _months) % {'number': _months}
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
s = _('1 week')
_weeks = int(self.day / 7) s = self.ngettext("%(number)s week", "%(number)s weeks", _weeks) % {'number': _weeks}
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
s = _('%(number)s days')%{'number': self.day}
s = self.ngettext('%(number)s day', '%(number)s days', self.day) % {'number': self.day}
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
return _('tomorrow')
return self._('tomorrow')
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
return _('yesterday')
return self._('yesterday')
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
s = _('%(number)s hours')%{'number': self.hour}
s = self.ngettext('%(number)s hour', '%(number)s hours', self.hour) % {'number': self.hour}
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours')
s = self._('an hour') elif _quarters == 2: s = self._('1 1/2 hours')
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
s = _('1 %(number)s/4 hours')%{'number': self.minute/15}
s = self.ngettext('1 %(number)s/4 hours', '1 %(number)s/4 hours', _quarters) % {'number': _quarters}
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
return _('in a moment')
return self._('in a moment')
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
return _('just now')
return self._('just now')
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
s = _('1 minute')
s = self._('1 minute')
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s
s = self.ngettext('%(number)s minute', '%(number)s minutes', self.minute) % {'number': self.minute} elif _quarters == 2: s = self._('1/2 an hour') else: s = self.ngettext('%(number)s/4 hours', '%(number)s/4 hours', _quarters) % {'number': _quarters} if self.sign < 0: s = self._('%s ago') % s else: s = self._('in %s') % s
def pretty(self): ''' print up the date date using one of these nice formats.. ''' if self.year: if self.year == 1: s = _('1 year') else: s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: if int(days/30) > 1: s = _('%(number)s months')%{'number': int(days/30)} else: s = _('1 month') else: s = _('%(number)s weeks')%{'number': int(days/7)} elif self.day > 7: s = _('1 week') elif self.day > 1: s = _('%(number)s days')%{'number': self.day} elif self.day == 1 or self.hour > 12: if self.sign > 0: return _('tomorrow') else: return _('yesterday') elif self.hour > 1: s = _('%(number)s hours')%{'number': self.hour} elif self.hour == 1: if self.minute < 15: s = _('an hour') elif self.minute/15 == 2: s = _('1 1/2 hours') else: s = _('1 %(number)s/4 hours')%{'number': self.minute/15} elif self.minute < 1: if self.sign > 0: return _('in a moment') else: return _('just now') elif self.minute == 1: s = _('1 minute') elif self.minute < 15: s = _('%(number)s minutes')%{'number': self.minute} elif int(self.minute/15) == 2: s = _('1/2 an hour') else: s = _('%(number)s/4 hour')%{'number': int(self.minute/15)} if self.sign < 0: s = s + _(' ago') else: s = _('in ') + s return s
return '%s weeks'%self.day
return '1 week'
def pretty(self, threshold=('d', 5)): ''' print up the date date using one of these nice formats.. < 1 minute < 15 minutes < 30 minutes < 1 hour < 12 hours < 1 day otherwise, return None (so a full date may be displayed) ''' if self.year or self.month > 2: return None if self.month: days = (self.month * 30) + self.day if days > 28: return '%s months'%int(days/30) else: return '%s weeks'%int(days/7) if self.day > 7: return '%s weeks'%self.day if self.day > 1: return '%s days'%self.day if self.day == 1 or self.hour > 12: return 'yesterday' if self.hour > 1: return '%s hours'%self.hour if self.hour == 1: if self.minute < 15: return 'an hour' quart = self.minute/15 if quart == 2: return '1 1/2 hours' return '1 %s/4 hours'%quart if self.minute < 1: return 'just now' if self.minute == 1: return '1 minute' if self.minute < 15: return '%s minutes'%self.minute quart = int(self.minute/15) if quart == 2: return '1/2 an hour' return '%s/4 hour'%quart
value = self.cl.get(self.nodeid, property)
if isinstance(propclass, hyperdb.Link: value = [self.cl.get(self.nodeid, property)] else: value = self.cl.get(self.nodeid, property)
def __call__(self, property, **args): propclass = self.properties[property] if self.nodeid: value = self.cl.get(self.nodeid, property) elif self.filterspec is not None: value = self.filterspec.get(property, []) else: value = [] if (isinstance(propclass, hyperdb.Link) or isinstance(propclass, hyperdb.Multilink)): linkcl = self.db.classes[propclass.classname] l = [] k = linkcl.labelprop() for optionid in linkcl.list(): option = linkcl.get(optionid, k) if optionid in value or option in value: checked = 'checked' else: checked = '' l.append('%s:<input type="checkbox" %s name="%s" value="%s">'%( option, checked, property, option)) return '\n'.join(l) return '[Checklist: not a link]'
if (isinstance(propclass, hyperdb.Link) or isinstance(propclass, hyperdb.Multilink)): linkcl = self.db.classes[propclass.classname] l = [] k = linkcl.labelprop() for optionid in linkcl.list(): option = linkcl.get(optionid, k) if optionid in value or option in value: checked = 'checked' else: checked = '' l.append('%s:<input type="checkbox" %s name="%s" value="%s">'%( option, checked, property, option)) return '\n'.join(l) return '[Checklist: not a link]'
linkcl = self.db.classes[propclass.classname] l = [] k = linkcl.labelprop() for optionid in linkcl.list(): option = linkcl.get(optionid, k) if optionid in value or option in value: checked = 'checked' else: checked = '' l.append('%s:<input type="checkbox" %s name="%s" value="%s">'%( option, checked, property, option)) return '\n'.join(l)
def __call__(self, property, **args): propclass = self.properties[property] if self.nodeid: value = self.cl.get(self.nodeid, property) elif self.filterspec is not None: value = self.filterspec.get(property, []) else: value = [] if (isinstance(propclass, hyperdb.Link) or isinstance(propclass, hyperdb.Multilink)): linkcl = self.db.classes[propclass.classname] l = [] k = linkcl.labelprop() for optionid in linkcl.list(): option = linkcl.get(optionid, k) if optionid in value or option in value: checked = 'checked' else: checked = '' l.append('%s:<input type="checkbox" %s name="%s" value="%s">'%( option, checked, property, option)) return '\n'.join(l) return '[Checklist: not a link]'
(nodeid, date_stamp, self.journaltag, action, params) = entry
(nodeid, date_stamp, user, action, params) = entry
def getjournal(self, classname, nodeid): ''' get the journal for id ''' # attempt to open the journal - in some rare cases, the journal may # not exist try: db = bsddb.btopen(os.path.join(self.dir, 'journals.%s'%classname), 'r') except bsddb.error, error: if error.args[0] != 2: raise return [] # mor handling of bad journals if not db.has_key(nodeid): return [] journal = marshal.loads(db[nodeid]) res = [] for entry in journal: (nodeid, date_stamp, self.journaltag, action, params) = entry date_obj = date.Date(date_stamp) res.append((nodeid, date_obj, self.journaltag, action, params)) db.close() return res
res.append((nodeid, date_obj, self.journaltag, action, params))
res.append((nodeid, date_obj, user, action, params))
def getjournal(self, classname, nodeid): ''' get the journal for id ''' # attempt to open the journal - in some rare cases, the journal may # not exist try: db = bsddb.btopen(os.path.join(self.dir, 'journals.%s'%classname), 'r') except bsddb.error, error: if error.args[0] != 2: raise return [] # mor handling of bad journals if not db.has_key(nodeid): return [] journal = marshal.loads(db[nodeid]) res = [] for entry in journal: (nodeid, date_stamp, self.journaltag, action, params) = entry date_obj = date.Date(date_stamp) res.append((nodeid, date_obj, self.journaltag, action, params)) db.close() return res
sortfunc = self.make_sort_function(propclass.classname)
def do_field(self, property, size=None, showid=0): ''' display a property like the plain displayer, but in a text field to be edited
options = linkcl.list() options.sort(sortfunc)
if linkcl.getprops().has_key('order'): sort_on = 'order' else: sort_on = linkcl.labelprop() options = linkcl.filter(None, {}, [sort_on], [])
def do_field(self, property, size=None, showid=0): ''' display a property like the plain displayer, but in a text field to be edited
options = linkcl.list() options.sort(sortfunc)
if linkcl.getprops().has_key('order'): sort_on = 'order' else: sort_on = linkcl.labelprop() options = linkcl.filter(None, {}, [sort_on], [])
def do_menu(self, property, size=None, height=None, showid=0, additional=[]): ''' For a Link/Multilink property, display a menu of the available choices
journaldate = str(date.Date(journaldate))
journaldate = date.Date(journaldate)
def add_new_columns_v2(self): '''While we're adding the actor column, we need to update the tables to have the correct datatypes.''' for klass in self.classes.values(): cn = klass.classname properties = klass.getprops() old_spec = self.database_schema['tables'][cn]
self.save_journal(cn, cols, nodeid, journaldate,
self.save_journal(cn, cols, nodeid, dc(journaldate),
def add_new_columns_v2(self): '''While we're adding the actor column, we need to update the tables to have the correct datatypes.''' for klass in self.classes.values(): cn = klass.classname properties = klass.getprops() old_spec = self.database_schema['tables'][cn]
def pt_html(context=5):
def pt_html(context=5, i18n=None): _ = get_translator(i18n)
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>',
exc_info = [esc(str(value)) for value in sys.exc_info()[:2]] l = [_('<h1>Templating Error</h1>\n' '<p><b>%(exc_type)s</b>: %(exc_value)s</p>\n' '<p class="help">Debugging information follows</p>' ) % {'exc_type': exc_info[0], 'exc_value': exc_info[1]},
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info))))
s.append(_('<li>"%(name)s" (%(info)s)</li>') % {'name': name, 'info': esc(repr(info))})
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s))
l.append(_('<li>Looking for "%(name)s", ' 'current path:<ol>%(path)s</ol></li>' ) % {'name': ti.name, 'path': s})
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
l.append('<li>In %s</li>'%esc(str(ti)))
l.append(_('<li>In %s</li>') % esc(str(ti)))
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
s = 'A problem occurred in your template "%s".'%str(context.id)
s = _('A problem occurred in your template "%s".') \ % str(context.id)
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
l.append(''' <li>While evaluating the %r expression on line %d
l.append(_(''' <li>While evaluating the %(info)r expression on line %(line)d
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
%s %s
%(globals)s %(locals)s
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
'''%(info, context.position[0], niceDict(' ', context.global_vars), niceDict(' ', context.local_vars)))
''') % { 'info': info, 'line': context.position[0], 'globals': niceDict(' ', context.global_vars), 'locals': niceDict(' ', context.local_vars) })
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
<tr><th class="header" align="left">Full traceback:</th></tr>
<tr><th class="header" align="left">%s</th></tr>
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
</table>'''%cgi.escape(''.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))))
</table>''' % (_('Full traceback:'), cgi.escape(''.join( traceback.format_exception(*sys.exc_info()) ))))
def pt_html(context=5): esc = cgi.escape l = ['<h1>Templating Error</h1>', '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), esc(str(sys.exc_value))), '<p class="help">Debugging information follows</p>', '<ol>',] from roundup.cgi.PageTemplates.Expressions import TraversalError t = inspect.trace(context) t.reverse() for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] if isinstance(ti, TraversalError): s = [] for name, info in ti.path: s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) s = '\n'.join(s) l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( ti.name, s)) else: l.append('<li>In %s</li>'%esc(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts s = 'A problem occurred in your template "%s".'%str(context.id) if context._v_errors: s = s + '<br>' + '<br>'.join( [esc(x) for x in context._v_errors]) l.append('<li>%s</li>'%s) elif len(ts) == 3: supp, context, info = ts l.append('''
def html(context=5):
def html(context=5, i18n=None): _ = get_translator(i18n)
def html(context=5): etype, evalue = sys.exc_type, sys.exc_value if type(etype) is types.ClassType: etype = etype.__name__ pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable head = pydoc.html.heading( '<font size=+1><strong>%s</strong>: %s</font>'%(etype, evalue), '#ffffff', '#777777', pyver) head = head + (_('<p>A problem occurred while running a Python script. ' 'Here is the sequence of function calls leading up to ' 'the error, with the most recent (innermost) call first. ' 'The exception attributes are:')) indent = '<tt><small>%s</small>&nbsp;</tt>' % ('&nbsp;' * 5) traceback = [] for frame, file, lnum, func, lines, index in inspect.trace(context): if file is None: link = '''&lt;file is None - probably inside <tt>eval</tt> or <tt>exec</tt>&gt;''' else: file = os.path.abspath(file) link = '<a href="file:%s">%s</a>' % (file, pydoc.html.escape(file)) args, varargs, varkw, locals = inspect.getargvalues(frame) if func == '?': call = '' else: call = 'in <strong>%s</strong>' % func + inspect.formatargvalues( args, varargs, varkw, locals, formatvalue=lambda value: '=' + pydoc.html.repr(value)) level = '''
'<font size=+1><strong>%s</strong>: %s</font>'%(etype, evalue),
_('<font size=+1><strong>%(exc_type)s</strong>: %(exc_value)s</font>') % {'exc_type': etype, 'exc_value': evalue},
def html(context=5): etype, evalue = sys.exc_type, sys.exc_value if type(etype) is types.ClassType: etype = etype.__name__ pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable head = pydoc.html.heading( '<font size=+1><strong>%s</strong>: %s</font>'%(etype, evalue), '#ffffff', '#777777', pyver) head = head + (_('<p>A problem occurred while running a Python script. ' 'Here is the sequence of function calls leading up to ' 'the error, with the most recent (innermost) call first. ' 'The exception attributes are:')) indent = '<tt><small>%s</small>&nbsp;</tt>' % ('&nbsp;' * 5) traceback = [] for frame, file, lnum, func, lines, index in inspect.trace(context): if file is None: link = '''&lt;file is None - probably inside <tt>eval</tt> or <tt>exec</tt>&gt;''' else: file = os.path.abspath(file) link = '<a href="file:%s">%s</a>' % (file, pydoc.html.escape(file)) args, varargs, varkw, locals = inspect.getargvalues(frame) if func == '?': call = '' else: call = 'in <strong>%s</strong>' % func + inspect.formatargvalues( args, varargs, varkw, locals, formatvalue=lambda value: '=' + pydoc.html.repr(value)) level = '''
link = '''&lt;file is None - probably inside <tt>eval</tt> or <tt>exec</tt>&gt;'''
link = _("&lt;file is None - probably inside <tt>eval</tt> " "or <tt>exec</tt>&gt;")
def html(context=5): etype, evalue = sys.exc_type, sys.exc_value if type(etype) is types.ClassType: etype = etype.__name__ pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable head = pydoc.html.heading( '<font size=+1><strong>%s</strong>: %s</font>'%(etype, evalue), '#ffffff', '#777777', pyver) head = head + (_('<p>A problem occurred while running a Python script. ' 'Here is the sequence of function calls leading up to ' 'the error, with the most recent (innermost) call first. ' 'The exception attributes are:')) indent = '<tt><small>%s</small>&nbsp;</tt>' % ('&nbsp;' * 5) traceback = [] for frame, file, lnum, func, lines, index in inspect.trace(context): if file is None: link = '''&lt;file is None - probably inside <tt>eval</tt> or <tt>exec</tt>&gt;''' else: file = os.path.abspath(file) link = '<a href="file:%s">%s</a>' % (file, pydoc.html.escape(file)) args, varargs, varkw, locals = inspect.getargvalues(frame) if func == '?': call = '' else: call = 'in <strong>%s</strong>' % func + inspect.formatargvalues( args, varargs, varkw, locals, formatvalue=lambda value: '=' + pydoc.html.repr(value)) level = '''
call = 'in <strong>%s</strong>' % func + inspect.formatargvalues(
call = _('in <strong>%s</strong>') % func + inspect.formatargvalues(
def html(context=5): etype, evalue = sys.exc_type, sys.exc_value if type(etype) is types.ClassType: etype = etype.__name__ pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable head = pydoc.html.heading( '<font size=+1><strong>%s</strong>: %s</font>'%(etype, evalue), '#ffffff', '#777777', pyver) head = head + (_('<p>A problem occurred while running a Python script. ' 'Here is the sequence of function calls leading up to ' 'the error, with the most recent (innermost) call first. ' 'The exception attributes are:')) indent = '<tt><small>%s</small>&nbsp;</tt>' % ('&nbsp;' * 5) traceback = [] for frame, file, lnum, func, lines, index in inspect.trace(context): if file is None: link = '''&lt;file is None - probably inside <tt>eval</tt> or <tt>exec</tt>&gt;''' else: file = os.path.abspath(file) link = '<a href="file:%s">%s</a>' % (file, pydoc.html.escape(file)) args, varargs, varkw, locals = inspect.getargvalues(frame) if func == '?': call = '' else: call = 'in <strong>%s</strong>' % func + inspect.formatargvalues( args, varargs, varkw, locals, formatvalue=lambda value: '=' + pydoc.html.repr(value)) level = '''
if not os.getuid():
if os.getuid():
def setgid(group): if group is None: return if not hasattr(os, 'setgid'): return # if root, setgid to the running user if not os.getuid(): print _('WARNING: ignoring "-g" argument, not root') return try: import grp except ImportError: raise ValueError, _("Can't change groups - no grp module") try: try: gid = int(group) except ValueError: gid = grp.getgrnam(group)[2] else: grp.getgrgid(gid) except KeyError: raise ValueError,_("Group %(group)s doesn't exist")%locals() os.setgid(gid)
v = int(value)
v = float(value)
def set_inner(self, nodeid, **propvalues): '''Called outside of auditors''' isnew = 0 if propvalues.has_key('#ISNEW'): isnew = 1 del propvalues['#ISNEW']
where[propname] = int(value)
if type(value) is _LISTTYPE: orcriteria[propname] = [float(v) for v in value] else: where[propname] = float(value)
def filter(self, search_matches, filterspec, sort=(None,None), group=(None,None)): '''Return a list of the ids of the active nodes in this class that match the 'filter' spec, sorted by the group spec and then the sort spec
value = int(value)
value = float(value)
def import_list(self, propnames, proplist): ''' Import a node - all information including "id" is present and should not be sanity checked. Triggers are not triggered. The journal should be initialised using the "creator" and "creation" information.
hyperdb.Number : 'I',
hyperdb.Number : 'D',
def getNumber(number): if number == 0: res = None elif number < 0: res = number else: res = number - 1 return res
path = __file__ for i in range(5): path = os.path.dirname(path) tdir = os.path.join(path, 'share', 'roundup', 'templates') if os.path.isdir(tdir): templates = listTemplates(tdir) else: templates = {}
templates = {} for N in 4, 5: path = __file__ for i in range(N): path = os.path.dirname(path) tdir = os.path.join(path, 'share', 'roundup', 'templates') if os.path.isdir(tdir): templates = listTemplates(tdir) break
def listTemplates(self): ''' List all the available templates.
if tracker_home is not None:
if tracker_home is None: tracker_locale = None else:
def get_translation(language=None, tracker_home=None, translation_class=RoundupTranslations, null_translation_class=RoundupNullTranslations
else: tracker_locale = None
def get_translation(language=None, tracker_home=None, translation_class=RoundupTranslations, null_translation_class=RoundupNullTranslations
for mofile in mofiles:
for mofile in mofiles[1:]:
def get_translation(language=None, tracker_home=None, translation_class=RoundupTranslations, null_translation_class=RoundupNullTranslations
user = 'anonymous'
def determine_user(self): ''' Determine who the user is ''' # determine the uid to use self.opendb('admin')
_svc_name_ = "Roundup Bug Tracker"
_svc_name_ = "roundup"
def get_server(self): """Return HTTP server object to run""" # redirect stdout/stderr to our logfile # this is done early to have following messages go to this logfile if self["LOGFILE"]: # appending, unbuffered sys.stdout = sys.stderr = open(self["LOGFILE"], 'a', 0) # we don't want the cgi module interpreting the command-line args ;) sys.argv = sys.argv[:1] # build customized request handler class class RequestHandler(RoundupRequestHandler): LOG_IPADDRESS = not self["LOG_HOSTNAMES"] TRACKER_HOMES = dict(self.trackers()) # obtain request server class if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES: print _("Multiprocess mode \"%s\" is not available, " "switching to single-process") % self["MULTIPROCESS"] self["MULTIPROCESS"] = "none" server_class = BaseHTTPServer.HTTPServer elif self["MULTIPROCESS"] == "fork": class ForkingServer(SocketServer.ForkingMixIn, BaseHTTPServer.HTTPServer): pass server_class = ForkingServer elif self["MULTIPROCESS"] == "thread": class ThreadingServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): pass server_class = ThreadingServer else: server_class = BaseHTTPServer.HTTPServer # obtain server before changing user id - allows to # use port < 1024 if started as root try: httpd = server_class((self["HOST"], self["PORT"]), RequestHandler) except socket.error, e: if e[0] == errno.EADDRINUSE: raise socket.error, \ _("Unable to bind to port %s, port already in use.") \ % self["PORT"] raise # change user and/or group setgid(self["GROUP"]) setuid(self["USER"]) # return the server return httpd
must configure the rest of the options by changing the constants of this program. You will at least configure one tracker in the TRACKER_HOMES variable. This option is mutually exclusive from the rest. Typing "roundup-server -c help" shows Windows Services
must use configuration file to specify tracker homes. Logfile option is required to run Roundup Tracker service. Typing "roundup-server -c help" shows Windows Services
def usage(message=''): if RoundupService: os_part = \
-v prints the Roundup version number and exits -C <fname> use configuration file -n <name> sets the host name of the Roundup web server instance -p <port> sets the port to listen on (default: %(port)s)
-v print the Roundup version number and exit -h print this text and exit -S create or update configuration file and exit -C <fname> use configuration file <fname> -n <name> set the host name of the Roundup web server instance -p <port> set the port to listen on (default: %(port)s)
def usage(message=''): if RoundupService: os_part = \
See the "admin_guide" in the Roundup "doc" directory.
Roundup Server configuration file has common .ini file format. Configuration file created with 'roundup-server -S' contains detailed explanations for each option. Please see that file for option descriptions.
def usage(message=''): if RoundupService: os_part = \
short_options = "c:C:"
short_options = "cC:"
def run(port=undefined, success_message=None): ''' Script entry point - handle args and figure out what to to. ''' # time out after a minute if we can if hasattr(socket, 'setdefaulttimeout'): socket.setdefaulttimeout(60) config = ServerConfig() # additional options short_options = "hvS" if RoundupService: short_options += 'c' try: (optlist, args) = config.getopt(sys.argv[1:], short_options, ("help", "version", "save-config",)) except (getopt.GetoptError, configuration.ConfigurationError), e: usage(str(e)) return # if running in windows service mode, don't do any other stuff if ("-c", "") in optlist: # acquire command line options recognized by service short_options = "c:C:" long_options = ["config"] for (long_name, short_name) in config.OPTIONS.items(): short_options += short_name long_name = long_name.lower().replace("_", "-") if short_name[-1] == ":": long_name += "=" long_options.append(long_name) optlist = getopt.getopt(sys.argv[1:], short_options, long_options)[0] svc_args = [] for (opt, arg) in optlist: if opt in ("-C", "-l"): # make sure file name is absolute svc_args.extend((opt, os.path.abspath(arg))) elif opt in ("--config", "--logfile"): # ditto, for long options svc_args.append("=".join(opt, os.path.abspath(arg))) elif opt != "-c": svc_args.extend(opt) RoundupService._exe_args_ = " ".join(svc_args) # pass the control to serviceutil win32serviceutil.HandleCommandLine(RoundupService, argv=sys.argv[:1] + args) return # add tracker names from command line. # this is done early to let '--save-config' handle the trackers. if args: for arg in args: try: name, home = arg.split('=') except ValueError: raise ValueError, _("Instances must be name=home") config.add_option(TrackerHomeOption(config, "trackers", name)) config["TRACKERS_" + name.upper()] = home # handle remaining options if optlist: for (opt, arg) in optlist: if opt in ("-h", "--help"): usage() elif opt in ("-v", "--version"): print '%s (python %s)' % (roundup_version, sys.version.split()[0]) elif opt in ("-S", "--save-config"): config.save() print _("Configuration saved to %s") % config.filepath # any of the above options prevent server from running return # port number in function arguments overrides config and command line if port is not undefined: config.PORT = port # fork the server from our parent if a pidfile is specified if config["PIDFILE"]: if not hasattr(os, 'fork'): print _("Sorry, you can't run the server as a daemon" " on this Operating System") sys.exit(0) else: daemonize(config["PIDFILE"]) # create the server httpd = config.get_server() if success_message: print success_message else: print _('Roundup server started on %(HOST)s:%(PORT)s') \ % config try: httpd.serve_forever() except KeyboardInterrupt: print 'Keyboard Interrupt: exiting'