9 from optparse import OptionParser
10 from ConfigParser import SafeConfigParser
12 # first off, parse the command line arguments
14 oparser = OptionParser()
16 "-c", "--conf", dest="conf",
17 help="location of config file"
20 (options, args) = oparser.parse_args()
22 # check for the configfile
26 if options.conf != None:
27 # does the file exist?
30 configfile = options.conf
32 # should exit here as the specified file doesn't exist
33 sys.stderr.write("Config file %s does not exist. Exiting.\n" %(options.conf,))
36 # check through the default locations
38 os.stat("%s/.rss2maildir.conf" %(os.environ["HOME"],))
39 configfile = "%s/.rss2maildir.conf" %(os.environ["HOME"],)
42 os.stat("/etc/rss2maildir.conf")
43 configfile = "/etc/rss2maildir.conf"
45 sys.stderr.write("No config file found. Exiting.\n")
48 # Right - if we've got this far, we've got a config file, now for the hard
51 scp = SafeConfigParser()
54 maildir_root = "RSSMaildir"
56 if scp.has_option("general", "maildir_root"):
57 maildir_root = scp.get("general", "maildir_root")
60 mode = os.stat(maildir_root)[stat.ST_MODE]
61 if not stat.S_ISDIR(mode):
62 sys.stderr.write("Maildir Root %s is not a directory\n" %(maildir_root))
66 os.mkdir(maildir_root)
68 sys.stderr.write("Couldn't create Maildir Root %s\n" %(maildir_root))
71 feeds = scp.sections()
73 feeds.remove("general")
78 # check if the directory exists
81 maildir = scp.get(section, "maildir")
85 maildir = urllib.urlencode(((section, maildir),)).split("=")[1]
86 maildir = os.path.join(maildir_root, maildir)
89 exists = os.stat(maildir)
90 if stat.S_ISDIR(exists[stat.ST_MODE]):
91 # check if there's a new, cur and tmp directory
93 mode = os.stat(os.path.join(maildir, "cur"))[stat.ST_MODE]
95 os.mkdir(os.path.join(maildir, "cur"))
96 if not stat.S_ISDIR(mode):
97 sys.stderr.write("Broken maildir: %s" %(maildir))
99 mode = os.stat(os.path.join(maildir, "tmp"))[stat.ST_MODE]
101 os.mkdir(os.path.join(maildir, "tmp"))
102 if not stat.S_ISDIR(mode):
103 sys.stderr.write("Broken maildir: %s" %(maildir))
105 mode = os.stat(os.path.join(maildir, "new"))[stat.ST_MODE]
106 if not stat.S_ISDIR(mode):
107 sys.stderr.write("Broken maildir: %s" %(maildir))
109 os.mkdir(os.path.join(maildir, "new"))
111 sys.stderr.write("Broken maildir: %s" %(maildir))
114 os.mkdir(os.path.join(maildir, "new"))
115 os.mkdir(os.path.join(maildir, "cur"))
116 os.mkdir(os.path.join(maildir, "tmp"))