~dushyant37/+junk/Archiver

« back to all changes in this revision

Viewing changes to Archiver/archiver.py

  • Committer: Dushyant Bansal
  • Date: 2011-10-06 13:28:44 UTC
  • Revision ID: dushyant37@gmail.com-20111006132844-m2c0co7mnh0vcrfw
Making it easy to install using setup.py install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import sys
2
 
import argparse
3
 
from storm.locals import *
4
 
from email import message_from_file, message_from_string
5
 
from HyperArch import Article,T
6
 
from i18n import initialize
7
 
 
8
 
initialize()
9
 
from core.i18n import _
10
 
#command: /bin/echo "/usr/bin/mhonarc -add -dbfile $PRIVATE_ARCHIVE_FILE_DIR/${listname}.mbox/mhonarc.db  
11
 
#-outdir $VAR_DIR/mhonarc/${listname} -stderr $LOG_DIR/mhonarc -stdout $LOG_DIR/mhonarc -spammode -umask 022"
12
 
#mhonarc -mbox
13
 
#$prefix/archives/private/yourmaillist.mbox/yourmaillist.mbox
14
 
 
15
 
#add a message into archives
16
 
def add(args, archiver):    
17
 
    #take msg as string from stdin
18
 
#    msg = message_from_string("""\
19
 
#From: "Dushyant" <db1@lists.example.org>
20
 
#To: test14@lists.example.com
21
 
#Subject: Re: new2  archived message
22
 
#Message-ID: <12460>
23
 
#In-Reply-To: <12459>
24
 
#Hi. this is the fist message
25
 
#""")
26
 
    msg = sys.stdin.read()
27
 
    print msg
28
 
    msg = message_from_string(msg)
29
 
    #Archive message
30
 
    archiver.archiveMsg(msg)
31
 
    
32
 
#convert a mbox file into sqlite db
33
 
def convert(args, archiver):
34
 
    archiver.mboxToDB(args.mbox)
35
 
        
36
 
def main():
37
 
    """bin/archiver"""
38
 
    # Create the basic parser and add all globally common options.
39
 
    parser = argparse.ArgumentParser(
40
 
        description="""ArchiverUI: Archives and manages messages from mailman mlists""",
41
 
        formatter_class=argparse.RawDescriptionHelpFormatter)
42
 
    
43
 
    parser.add_argument(
44
 
        '-v', '--version',
45
 
        action='version', version='1.0',
46
 
        help=_('Print this version string and exit'))
47
 
    
48
 
    parser.add_argument(
49
 
        '-C', '--config',
50
 
        help=_("""\
51
 
        Configuration file to use.  If not given, the environment variable
52
 
        MAILMAN_CONFIG_FILE is consulted and used if set.  If neither are
53
 
        given, a default configuration file is loaded."""))
54
 
    
55
 
    parser.add_argument(
56
 
        '-basedir', help=_('Specify the base directory which contains archives'))
57
 
    
58
 
    parser.add_argument(
59
 
        '-listname', help=_('Specify the listname to which this message belongs'))
60
 
   
61
 
    subparsers = parser.add_subparsers(title='Commands', 
62
 
                                   description='valid subcommands',
63
 
                                   help='additional help')
64
 
    
65
 
    add_parser = subparsers.add_parser('add', help='add a message to the archives')
66
 
    add_parser.set_defaults(func=add)
67
 
    
68
 
    convert_parser = subparsers.add_parser('convert', help='convert a mbox file containing messages into archives db')
69
 
    convert_parser.set_defaults(func=convert)
70
 
    convert_parser.add_argument(
71
 
        '-mbox', help=_('Specify the mbox file to be updated'))
72
 
    
73
 
    args = parser.parse_args()
74
 
    print type(args)
75
 
    if len(args.__dict__) == 0:
76
 
        # No arguments or subcommands were given.
77
 
        parser.print_help()
78
 
        parser.exit()
79
 
#    # Before actually performing the subcommand, we need to initialize the
80
 
#    # Mailman system, and in particular, we must read the configuration file.
81
 
#    config_file = os.getenv('MAILMAN_CONFIG_FILE')
82
 
#    if config_file is None:
83
 
#        config_file = args.config
84
 
#    initialize(config_file)
85
 
#    # Perform the subcommand option.
86
 
#    args.func(args)
87
 
    
88
 
    archiver  = T(basedir = args.basedir, mlist = args.listname)
89
 
    archiver.db_init()
90
 
#    args['msg'] = sys.stdin.read()
91
 
    args.func(args, archiver)
92
 
 
93
 
if __name__ == "__main__":
94
 
    main()
 
 
b'\\ No newline at end of file'