2
# -*- coding: iso-8859-15 -*-
5
# Author: Laudeci Oliveira <laudeci@gmail.com>
6
# Rafael Proença <cypherbios@ubuntu.com>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License as
10
# published by the Free Software Foundation; either version 2 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32
AOC_VERSION = 'aocversion'
33
DISTRIBUTION = 'distribution'
35
ARCHITECTURE = 'architecture'
38
class mediaBase(object):
39
"""This class is used as a base class to all media information classes."""
40
def __init__(self, filename="", media="CD1", totalmedia="1"):
41
util = utils.SystemInfo()
43
self.fileName = filename
44
self.aocversion = config.VERSION
45
self.distro = util.distro
46
self.codename = util.codename
47
self.arch = util.architecture
48
self.date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
50
self.totalmedia = totalmedia
51
self.disklabel = "APTonCD for " + self.distro + ' ' + self.codename + ' - ' + self.arch + ' (' + self.date + ') '
53
def __get_value(self,source, string, default = ''):
60
class mediaInfo(mediaBase):
61
"""This class writes some infomation about the media created."""
63
def __init__(self, filename=""):
64
super(mediaInfo,self).__init__(filename)
66
def __get_value(self,source, string, default = ''):
72
def infoFromFile(self):
73
if self.fileName == "":
74
return False , "File name cannot be empty."
76
if not os.path.isfile(self.fileName):
77
return False , "'" + self.fileName + "' doesn't exist."
79
aptfile=open(self.fileName)
80
aptdata=aptfile.read()
82
return False , "File doesn't seems to be valid."
84
infos = string.split(aptdata,"\n\n")
87
tmp=StringIO.StringIO(info)
89
self.aocversion = self.__get_value(p,AOC_VERSION)
90
self.distro = self.__get_value(p,DISTRIBUTION)
91
self.codename = self.__get_value(p,CODENAME)
92
self.arch = self.__get_value(p,ARCHITECTURE)
93
self.date = self.__get_value(p,FILE_DATE)
96
def compare_version(self):
97
util = utils.SystemInfo()
99
info = "This media was created in an %s %s system, and is not suitable for your running system (%s %s), please add a compatible APTonCD media created in an system like yours."
100
if self.distro != util.distro or self.codename != util.codename:
101
return False, (info % (self.distro,self.codename,util.distro,util.codename))
102
elif self.arch != util.architecture:
103
return False, (info % (self.codename, self.arch,util.codename, util.architecture))
106
except Exception, ex :
107
return False, str(ex)
113
mFile = open(self.fileName,"w")
114
mFile.write("aocversion: " + self.aocversion \
115
+ "\ndistribution: " + self.distro \
116
+ "\ncodename: " + self.codename \
117
+ "\narchitecture: " + self.arch \
118
+ "\ndate: " + self.date + "\n")
121
print "The file does not exist"
124
class aptDiskInfo(mediaBase):
125
"""This class writes some infomation for apt about de disk source."""
127
def __init__(self, filename="", media="CD1"):
128
super(aptDiskInfo,self).__init__(filename, media)
133
mFile = open(self.fileName,"w")
134
content = self.disklabel + self.media
138
print "The file does not exist"
141
class aptDiskDefines(mediaBase):
142
"""This class writes some infomation for apt about de disk source."""
144
def __init__(self, filename="", media="1", totalmedia="1"):
145
super(aptDiskDefines,self).__init__(filename, media, totalmedia)
150
mFile = open(self.fileName,"w")
151
content = "#define DISKNAME " + self.disklabel \
152
+ "\n#define TYPE binary" \
153
+ "\n#define TYPEbinary " + self.media \
154
+ "\n#define ARCH " + self.arch \
155
+ "\n#define ARCH" + self.arch + ' ' + self.media \
156
+ "\n#define DISKNUM " + self.media \
157
+ "\n#define DISKNUM" + self.media + ' ' + self.media \
158
+ "\n#define TOTALNUM " + self.media \
159
+ "\n#define TOTALNUM" + self.media + " " + self.media +"\n"
164
print "The file does not exist"