~ubuntu-branches/ubuntu/precise/aptoncd/precise

« back to all changes in this revision

Viewing changes to mediaInfo.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-17 22:04:26 UTC
  • mfrom: (1.1.1 upstream) (0.1.11 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090817220426-bhxr3a21ff6y8edm
Tags: 0.1.98+bzr109-0.1
* Non-maintainer upload
* New upstream release (Closes: #452205, #423480, #433915, #541047, #427003,
  #493647, #484636)
* debian/control: 
  - Changed python build dependencies to Build-Depends-Indep
  - Moved url from Description to Homepage
  - Changed Standards-Version to 3.8.2
  - Changed Maintainer to myself
  - Deleted dependency on deprecated mkisofs 
  - Deleted recommend of nautilus-cd-burner
* debian/copyright: Changed (C) to © to make lintian happy
* debian/rules: 
  - deleted deprecated dh_desktop
  - added get-orig-source target to get the latest source from lp
* data/aptoncd.desktop.in: Fixed error and deprecated values in Desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: iso-8859-15 -*-
3
 
# metaPackage.py
4
 
#  
5
 
#  Author: Laudeci Oliveira <laudeci@gmail.com>
6
 
#          Rafael Proença   <cypherbios@ubuntu.com>
7
 
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.
12
 
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.
17
 
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
21
 
#  USA
22
 
 
23
 
import config
24
 
import datetime
25
 
import os
26
 
import string
27
 
import utils
28
 
import sys
29
 
import rfc822
30
 
import StringIO
31
 
 
32
 
AOC_VERSION = 'aocversion'
33
 
DISTRIBUTION = 'distribution'
34
 
CODENAME = 'codename'
35
 
ARCHITECTURE = 'architecture'
36
 
FILE_DATE = 'date'
37
 
 
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()
42
 
                
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')
49
 
                self.media = media
50
 
                self.totalmedia = totalmedia
51
 
                self.disklabel = "APTonCD for " + self.distro + ' ' + self.codename + ' - ' + self.arch + ' (' + self.date + ') '
52
 
                
53
 
        def __get_value(self,source, string, default = ''):
54
 
                try:
55
 
                        return source[string]
56
 
                except:
57
 
                        return default
58
 
                
59
 
                
60
 
class mediaInfo(mediaBase):
61
 
        """This class writes some infomation about the media created."""
62
 
 
63
 
        def __init__(self, filename=""):
64
 
                super(mediaInfo,self).__init__(filename)
65
 
                
66
 
        def __get_value(self,source, string, default = ''):
67
 
                try:
68
 
                        return source[string]
69
 
                except:
70
 
                        return default
71
 
                
72
 
        def infoFromFile(self):
73
 
                if self.fileName == "":
74
 
                        return False , "File name cannot be empty."
75
 
                
76
 
                if not os.path.isfile(self.fileName):
77
 
                        return False , "'" + self.fileName + "' doesn't exist."
78
 
                try:
79
 
                        aptfile=open(self.fileName)
80
 
                        aptdata=aptfile.read()
81
 
                except IOError, msg:
82
 
                        return False , "File doesn't seems to be valid."
83
 
                
84
 
                infos = string.split(aptdata,"\n\n")
85
 
                for info in infos:
86
 
                        if info:
87
 
                                tmp=StringIO.StringIO(info)
88
 
                                p=rfc822.Message(tmp)
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)
94
 
                return True, None
95
 
 
96
 
        def compare_version(self):
97
 
                util = utils.SystemInfo()
98
 
                try :
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))
104
 
                        else:
105
 
                                return True, None
106
 
                except Exception, ex :
107
 
                        return False, str(ex)
108
 
                                        
109
 
                                
110
 
        def write(self):
111
 
                i= 0
112
 
                try:
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")
119
 
                        return True
120
 
                except IOError:
121
 
                        print "The file does not exist"
122
 
                        return False
123
 
                        
124
 
class aptDiskInfo(mediaBase):
125
 
        """This class writes some infomation for apt about de disk source."""
126
 
 
127
 
        def __init__(self, filename="", media="CD1"):
128
 
                super(aptDiskInfo,self).__init__(filename, media)
129
 
        
130
 
        def write(self):
131
 
                i= 0
132
 
                try:
133
 
                        mFile = open(self.fileName,"w")
134
 
                        content = self.disklabel + self.media
135
 
                        mFile.write(content)
136
 
                        return True
137
 
                except IOError:
138
 
                        print "The file does not exist"
139
 
                        return False
140
 
 
141
 
class aptDiskDefines(mediaBase):
142
 
        """This class writes some infomation for apt about de disk source."""
143
 
 
144
 
        def __init__(self, filename="", media="1", totalmedia="1"):
145
 
                super(aptDiskDefines,self).__init__(filename, media, totalmedia)
146
 
        
147
 
        def write(self):
148
 
                i= 0
149
 
                try:
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"
160
 
 
161
 
                        mFile.write(content)
162
 
                        return True
163
 
                except IOError:
164
 
                        print "The file does not exist"
165
 
                        return False