Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85136501
webmessageadmin.in
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 27, 00:52
Size
3 KB
Mime Type
text/x-python
Expires
Sun, Sep 29, 00:52 (2 d)
Engine
blob
Format
Raw Data
Handle
21133516
Attached To
R3600 invenio-infoscience
webmessageadmin.in
View Options
#!@PYTHON@
## -*- mode: python; coding: utf-8; -*-
##
## $Id$
##
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005 CERN.
##
## The CDSware is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## The CDSware is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""WebMessage Admin -- clean messages"""
__version__ = "$Id$"
try:
import getpass
import readline
import sys
pylibdir = "/home/cdsware/lib/python"
sys.path.append('%s' % pylibdir)
from cdsware.config import supportemail
from cdsware.webmessage_dblayer import clean_messages
from cdsware.dbquery import run_sql
except ImportError, e:
print "Error: %s" % e
import sys
sys.exit(1)
def usage(code, msg=''):
"""Print usage info."""
if msg:
sys.stderr.write("Error: %s.\n" % msg)
sys.stderr.write("WebMessage Admin -- cleans forgotten messages")
sys.stderr.write("Usage: %s [options] <command>\n" % sys.argv[0])
sys.stderr.write("Command options:\n")
sys.stderr.write(" <command> = clean\n")
sys.stderr.write("General options:\n")
sys.stderr.write(" -h, --help \t\t Print this help.\n")
sys.stderr.write(" -V, --version \t\t Print version information.\n")
sys.exit(code)
def main():
"""CLI to clean_messages. The function finds the needed
arguments in sys.argv.
If the number of arguments is wrong it prints help.
Return 1 on success, 0 on failure. """
alen = len(sys.argv)
action = ''
# print help if wrong arguments
if alen > 1 and sys.argv[1] in ["-h", "--help"]:
usage(0)
elif alen > 1 and sys.argv[1] in ["-V", "--version"]:
print __version__
sys.exit(0)
if alen != 2 or sys.argv[1] not in ['clean', 'send']:
usage(1)
# getting input from user
print 'User: ',
user = raw_input()
password = getpass.getpass()
# validating input
perform = 0
# check password
if user == supportemail:
perform = run_sql("""select * from user where email = '%s' and password = '%s' """ % (supportemail, password)) and 1 or 0
if not perform:
# wrong password or user not recognized
print 'User not authorized'
return perform
# perform chosen action
if sys.argv[1] == 'clean':
cleaned = clean_messages()
print 'Database cleaned. %i suppressed messages' % int(cleaned)
elif sys.argv[1] == 'send':
send(user)
return perform
def send(user):
try:
usernames = raw_input('To usernames (comma separated): ')
groupnames = raw_input('To groupnames (comma separated): ')
subject = raw_input('Subject: ')
body = raw_input('Message: ')
except KeyboardInterrupt:
print 'Interrupt. Your message was not sent'
if __name__ == '__main__':
main()
Event Timeline
Log In to Comment