123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import os
- import gettext
- import sys
- import sqlite3
- # -*- coding: utf8 -*-
- class conf(object):
- def __init__(self):
- self.values = {
- "database" : "stov.sqlite",
- "downloaddir" : str(os.environ['HOME']) + "/stov",
- "maxvideos" : "15",
- "mailhost" : "localhost",
- "mailto" : "root",
- "mailfrom" : "stov@localhost",
- "smtpport" : "25"
- }
- self.dbpath = str(os.environ['HOME']) + "/.stov/" + self.values["database"]
- def WriteConfig(self):
- try:
- self.configfile = open(str(os.environ['HOME']) + "/.stov/stov.config", "w")
- for key in self.values.iterkeys():
- self.configfile.write(key.upper() + "=" + self.values[key] + "\n")
- self.configfile.close()
- except IOError, os.error:
- print >> sys.stderr, _("Configuration could not be written, please check that the configuration directory exists and is writable")
-
- def CreateDB(self):
- try:
- self.__database = sqlite3.connect(self.dbpath)
- self.__dbcursor = self.__database.cursor()
- self.__dbcursor.execute("""CREATE TABLE subscriptions (
- id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
- title TEXT,
- name TEXT,
- type TEXT,
- searchstring TEXT,
- directory TEXT
- );""")
- self.__dbcursor.execute("""CREATE TABLE videos (
- id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
- title TEXT,
- description TEXT,
- ytid TEXT,
- subscription_id INTEGER,
- downloaded int
- );""")
- self.__database.commit()
- self.__database.close()
- except sqlite3.OperationalError:
- print >> sys.stderr, _("The database could not be created, please check that the configuration directory exists and is writable")
-
- def Initialize(self):
- try:
- os.mkdir(str(os.environ['HOME']) + "/.stov", 0750)
- self.WriteConfig()
- except os.error:
- print >> sys.stderr, _("Configuration directory could not be created, please check that your home directory exists and is writable")
- self.CreateDB()
-
- def ReadConfig(self):
- try:
- self.configfile = open(str(os.environ['HOME']) + "/.stov/stov.config", "r")
- except IOError:
- print >> sys.stderr, _("Configuration could not be read, please check that the configuration file exists and is readable")
- for lines in self.configfile:
- self.tmpline = lines.strip()
- self.tmplist = self.tmpline.split("=")
- self.values[self.tmplist[0].lower()] = self.tmplist[1]
- self.configfile.close()
- self.dbpath = str(os.environ['HOME']) + "/.stov/" + self.values["database"]
|