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

« back to all changes in this revision

Viewing changes to APTonCD/core/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
# -*- coding: utf-8 -*-
 
2
#############################################
 
3
#  Rafael Proença     <cypherbios@ubuntu.com>
 
4
#  Laudeci Oliveira    <laudeci@gmail.com>
 
5
#
 
6
#  Copyright 2006 APTonCD DevTeam.
 
7
#
 
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.
 
11
#
 
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
#############################################
 
17
import datetime
 
18
import os
 
19
import string
 
20
import sys
 
21
import rfc822
 
22
import StringIO
 
23
 
 
24
from APTonCD.core import constants
 
25
from APTonCD.core.utils import SystemInfo
 
26
 
 
27
AOC_VERSION = 'aocversion'
 
28
DISTRIBUTION = 'distribution'
 
29
CODENAME = 'codename'
 
30
ARCHITECTURE = 'architecture'
 
31
FILE_DATE = 'date'
 
32
 
 
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"):
 
36
                util = SystemInfo()
 
37
                
 
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')
 
44
                self.media = media
 
45
                self.totalmedia = totalmedia
 
46
                self.disklabel = "APTonCD for " + self.distro + ' ' + self.codename + ' - ' + self.arch + ' (' + self.date + ') '
 
47
                
 
48
        def __get_value(self,source, string, default = ''):
 
49
                try:
 
50
                        return source[string]
 
51
                except:
 
52
                        return default
 
53
                
 
54
                
 
55
class MediaInfo(mediaBase):
 
56
        """This class writes some infomation about the media created."""
 
57
 
 
58
        def __init__(self, filename=""):
 
59
                super(MediaInfo,self).__init__(filename)
 
60
                
 
61
        def __get_value(self,source, string, default = ''):
 
62
                try:
 
63
                        return source[string]
 
64
                except:
 
65
                        return default
 
66
                
 
67
        def infoFromFile(self):
 
68
                if self.fileName == "":
 
69
                        return False , "File name cannot be empty."
 
70
                
 
71
                if not os.path.isfile(self.fileName):
 
72
                        return False , "'" + self.fileName + "' doesn't exist."
 
73
                try:
 
74
                        aptfile=open(self.fileName, 'r')
 
75
                        aptdata=aptfile.read()
 
76
                except IOError, msg:
 
77
                        return False , "File doesn't seems to be valid."
 
78
                
 
79
                infos = string.split(aptdata,"\n\n")
 
80
                for info in infos:
 
81
                        if info:
 
82
                                tmp=StringIO.StringIO(info)
 
83
                                p=rfc822.Message(tmp)
 
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)
 
89
                return True, None
 
90
 
 
91
        def compare_version(self):
 
92
                util = SystemInfo()
 
93
                try :
 
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))
 
99
                        else:
 
100
                                return True, None
 
101
                except Exception, ex :
 
102
                        return False, str(ex)
 
103
                                        
 
104
                                
 
105
        def write(self):
 
106
                i= 0
 
107
                try:
 
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")
 
114
                        return True
 
115
                except IOError:
 
116
                        print "The file does not exist"
 
117
                        return False
 
118
                        
 
119
class aptDiskInfo(mediaBase):
 
120
        """This class writes some infomation for apt about de disk source."""
 
121
 
 
122
        def __init__(self, filename="", media="CD1"):
 
123
                super(aptDiskInfo,self).__init__(filename, media)
 
124
        
 
125
        def write(self):
 
126
                i= 0
 
127
                try:
 
128
                        mFile = open(self.fileName,"w")
 
129
                        content = self.disklabel + self.media
 
130
                        mFile.write(content)
 
131
                        return True
 
132
                except IOError:
 
133
                        print "The file does not exist"
 
134
                        return False
 
135
 
 
136
class aptDiskDefines(mediaBase):
 
137
        """This class writes some infomation for apt about de disk source."""
 
138
 
 
139
        def __init__(self, filename="", media="1", totalmedia="1"):
 
140
                super(aptDiskDefines,self).__init__(filename, media, totalmedia)
 
141
        
 
142
        def write(self):
 
143
                i= 0
 
144
                try:
 
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"
 
155
 
 
156
                        mFile.write(content)
 
157
                        return True
 
158
                except IOError:
 
159
                        print "The file does not exist"
 
160
                        return False