1
# -*- coding: utf-8 -*-
2
#############################################
3
# Rafael Proença <cypherbios@ubuntu.com>
4
# Laudeci Oliveira <laudeci@gmail.com>
6
# Copyright 2006 APTonCD DevTeam.
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published
10
# by the Free Software Foundation; version 2 only.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#############################################
24
from APTonCD.core import constants
25
from APTonCD.core.utils import SystemInfo
27
AOC_VERSION = 'aocversion'
28
DISTRIBUTION = 'distribution'
30
ARCHITECTURE = 'architecture'
33
class mediaBase(object):
34
"""This class is used as a base class to all media information classes."""
35
def __init__(self, filename="", media="CD1", totalmedia="1"):
38
self.fileName = filename
39
self.aocversion = constants.APP_VERSION
40
self.distro = util.distro
41
self.codename = util.codename
42
self.arch = util.architecture
43
self.date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
45
self.totalmedia = totalmedia
46
self.disklabel = "APTonCD for " + self.distro + ' ' + self.codename + ' - ' + self.arch + ' (' + self.date + ') '
48
def __get_value(self,source, string, default = ''):
55
class MediaInfo(mediaBase):
56
"""This class writes some infomation about the media created."""
58
def __init__(self, filename=""):
59
super(MediaInfo,self).__init__(filename)
61
def __get_value(self,source, string, default = ''):
67
def infoFromFile(self):
68
if self.fileName == "":
69
return False , "File name cannot be empty."
71
if not os.path.isfile(self.fileName):
72
return False , "'" + self.fileName + "' doesn't exist."
74
aptfile=open(self.fileName, 'r')
75
aptdata=aptfile.read()
77
return False , "File doesn't seems to be valid."
79
infos = string.split(aptdata,"\n\n")
82
tmp=StringIO.StringIO(info)
84
self.aocversion = self.__get_value(p,AOC_VERSION)
85
self.distro = self.__get_value(p,DISTRIBUTION)
86
self.codename = self.__get_value(p,CODENAME)
87
self.arch = self.__get_value(p,ARCHITECTURE)
88
self.date = self.__get_value(p,FILE_DATE)
91
def compare_version(self):
94
info = constants.MESSAGE_0070
95
if self.distro != util.distro or self.codename != util.codename:
96
return False, (info % (self.distro,self.codename,util.distro,util.codename))
97
elif self.arch != util.architecture:
98
return False, (info % (self.codename, self.arch,util.codename, util.architecture))
101
except Exception, ex :
102
return False, str(ex)
108
mFile = open(self.fileName,"w")
109
mFile.write("aocversion: " + self.aocversion \
110
+ "\ndistribution: " + self.distro \
111
+ "\ncodename: " + self.codename \
112
+ "\narchitecture: " + self.arch \
113
+ "\ndate: " + self.date + "\n")
116
print "The file does not exist"
119
class aptDiskInfo(mediaBase):
120
"""This class writes some infomation for apt about de disk source."""
122
def __init__(self, filename="", media="CD1"):
123
super(aptDiskInfo,self).__init__(filename, media)
128
mFile = open(self.fileName,"w")
129
content = self.disklabel + self.media
133
print "The file does not exist"
136
class aptDiskDefines(mediaBase):
137
"""This class writes some infomation for apt about de disk source."""
139
def __init__(self, filename="", media="1", totalmedia="1"):
140
super(aptDiskDefines,self).__init__(filename, media, totalmedia)
145
mFile = open(self.fileName,"w")
146
content = "#define DISKNAME " + self.disklabel \
147
+ "\n#define TYPE binary" \
148
+ "\n#define TYPEbinary " + self.media \
149
+ "\n#define ARCH " + self.arch \
150
+ "\n#define ARCH" + self.arch + ' ' + self.media \
151
+ "\n#define DISKNUM " + self.media \
152
+ "\n#define DISKNUM" + self.media + ' ' + self.media \
153
+ "\n#define TOTALNUM " + self.media \
154
+ "\n#define TOTALNUM" + self.media + " " + self.media +"\n"
159
print "The file does not exist"