lkd-planet/DJAGEN/branches/mustafa_branch/djagen/collector/configini.py

103 lines
2.9 KiB
Python
Raw Normal View History

2010-07-06 19:25:42 +03:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
from django.conf import settings
from djagen.collector.models import *
import ConfigParser
class Handler:
def __init__(self, id):
self.id = id
self.tmp_entries_ini = os.path.join(settings.MAIN_PATH, 'tmp_ini', 'tmp_entries.ini')
2010-09-02 12:29:59 +03:00
self.config_header_ini = os.path.join(settings.MAIN_PATH, 'gezegen', 'config_header.ini')
2010-07-06 19:25:42 +03:00
self.config_entries_ini = os.path.join(settings.MAIN_PATH, 'gezegen', 'config_entries.ini')
def __set_values(self):
author = Authors.objects.get(author_id = self.id)
if not author.is_approved:
return False
2010-09-02 12:29:59 +03:00
self.name = author.author_name
self.surname = author.author_surname
2010-07-06 19:25:42 +03:00
self.face = author.author_face
self.url = author.channel_url
2010-09-02 12:29:59 +03:00
labels = {
author.label_personal:'Personal',
author.label_lkd: 'LKD',
author.label_community: 'Community',
author.label_eng: 'Eng',
}
2010-07-06 19:25:42 +03:00
label_li = [k for k,v in labels.iteritems() if v==1]
self.author_labels = " ".join(label_li)
return True
def create_tmp_entries(self):
if not self.__set_values(): return
config_entries = open(self.config_entries_ini)
tmp_entries = open(self.tmp_entries_ini, 'w')
2010-09-02 12:29:59 +03:00
config_header = open(self.config_header_ini)
2010-07-06 19:25:42 +03:00
Config = ConfigParser.ConfigParser()
Config.read(self.config_entries_ini)
sections = Config.sections()
2010-09-02 12:29:59 +03:00
header = config_header.read()
config_header.close()
tmp_entries.write(header)
2010-07-06 19:25:42 +03:00
for section in sections:
2010-09-02 12:29:59 +03:00
if (section == 'Planet'):
continue
2010-07-06 19:25:42 +03:00
config_name = Config.get(section, 'name')
config_label = Config.get(section, 'label')
config_id = Config.get(section, 'id')
config_url = section
try:
config_face = Config.get(section, 'face')
except:
config_face = None
if config_id == self.id:
url = self.url
face = self.face
name = self.name
2010-09-02 12:29:59 +03:00
surname = self.surname
2010-07-06 19:25:42 +03:00
label = self.author_labels
id = self.id
else:
url = config_url
face = config_face
name = config_name
2010-09-02 12:29:59 +03:00
surname = config_name
2010-07-06 19:25:42 +03:00
label = config_label
id = config_id
2010-09-02 12:29:59 +03:00
s = '['+url+']' + '\n'
2010-07-06 19:25:42 +03:00
s += 'name = ' + name + '\n'
2010-09-02 12:29:59 +03:00
s += 'surname = ' + surname + '\n'
2010-07-06 19:25:42 +03:00
s += 'label = ' + label + '\n'
if face:
s += 'face = ' + face + '\n'
s += 'id = ' + id + '\n' + '\n'
tmp_entries.write(s)
tmp_entries.close()