File: config.py

package info (click to toggle)
aptoncd 0.1-1.2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,572 kB
  • ctags: 544
  • sloc: python: 3,125; xml: 1,216; makefile: 125; sh: 6
file content (97 lines) | stat: -rw-r--r-- 2,372 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

import os
#import gtk
from ConfigParser import RawConfigParser as ConfigParser

_config = ConfigParser()
get = _config.get
set = _config.set
getboolean = _config.getboolean
getint = _config.getint
getfloat = _config.getfloat
write = _config.write
options = _config.options

# -- dirs and files --
CONFIG_DIR  = os.path.expanduser("~/.aptoncd/")
if not os.path.isdir(CONFIG_DIR):
    os.makedirs(CONFIG_DIR)
CONFIG_FILE  = os.path.join(CONFIG_DIR, "config")

# -- some variables --
I18N_APP = "aptoncd"
I18N_DIR = "locale/"
GUI	= "aptoncd.glade"
VERSION = "0.1"
XML_FILE = os.path.join(CONFIG_DIR, 'conf.xml')
XML_CONTENTS = "content.xml"

# documentation directory
import locale
language = locale.setlocale(locale.LC_ALL, '')
end = language.find('.')
language = language[:end]
DOCDIR		= "doc/"
if os.path.isdir(DOCDIR+language):
	DOC	= DOCDIR + language+ "/index.xml"
else:
	DOC	= DOCDIR+ "C/index.xml"

# list constants
(LIST_INSTALL, LIST_CONTENTS, LIST_NAME, LIST_SHORTDESC,
 LIST_VERSION, LIST_LONG_DESCR, LIST_PKG) = range(7)

# listStore constants
(C_CHECKED, C_TITLE, C_CUSTOM, C_PKG, C_CANCHECK,C_DISABLED) = range(6) 

CD = 695 * 1024 * 1024
DVD = 4500 * 1024 * 1024

LOCAL_APT_FOLDER = "/var/cache/apt/archives/"

# Don't create un-used temporary directory.
#TMP_PATH = "/tmp/aptoncd/"
#if not os.path.isdir(TMP_PATH):
#    os.makedirs(TMP_PATH)

# -- write config --
def write(filename):
    if isinstance(filename, str):
        if not os.path.isdir(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))
        f = file(filename, "w")
    else: f = filename
    _config.write(f)
    f.close()

# -- load default values --
def init(*rc_files):
    initial = {
        # Configuration defaults

        "cache":
        {
            "isofile": "aptoncd.iso",
            "to": os.path.expanduser("~/aptoncd/"),
            "packages": os.path.expanduser("~/aptoncd/") + "packages/",
            "metapackage": "False"
        },
        
         "misc":
         {
           "version": "0.1",
         }

    }

    for section, values in initial.iteritems():
        _config.add_section(section)
        for key, value in values.iteritems():
            _config.set(section, key, value)

    _config.read(rc_files)

def state(arg):
    return _config.getboolean("settings", arg)