summaryrefslogtreecommitdiff
blob: aca345320a5da573c558ebd7695e8bd2c597c44c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright John N. Laliberte <allanonjl@gentoo.org>
# LICENSE - GPL2

# simple cache module

# This module will store information about the packages we read off of the gnome ftp.
# This way we don't have to constantly contact the GNOME ftp during the development process
# of this program.

class SimpleCache:
    
    def __init__(self):
        self.filename = "cache.txt"
        self.write_queue = []
    
    def write_to_queue(self, release_version, latest_version):
        self.write_queue.append(release_version + "," + latest_version)
    
    def append(self, list_of_lines):
        try:
            # open file stream
            file = open(self.filename, "a")
        except IOError:
            print "There was an error writing to"+self.filename
            sys.exit()
    
        for line in list_of_lines:
            file.write(line+"\n")
        
        file.close()
    
    def flush_queue(self):
        self.append(self.write_queue)
    
    
class FileStuff:
    def __init__(self, filename):
        self.filename = filename
        self.lines = []
        
    def read(self):
        file = self.open("r")
        # read the file in line by line, and then return it
        for line in file.readlines():
            # replace the newline characters
            line = string.replace(line,'\n','')
            # add it to the collection
            self.lines.append(line)
        file.close()
        
        return self.lines
        
    def write(self, list_of_lines):
        try:
            # open file stream
            file = self.open("w")
        except IOError:
            print "There was an error writing to"+self.filename
            sys.exit()
    
        for line in list_of_lines:
            file.write(line+"\n")
        
        file.close()
    
    def append(self, list_of_lines):
        try:
            # open file stream
            file = self.open("a")
        except IOError:
            print "There was an error writing to"+self.filename
            sys.exit()
    
        for line in list_of_lines:
            file.write(line+"\n")
        
        file.close()
            
    def open(self, type):
        try:
            file = open(self.filename, type)
            return file
        except IOError:
            print "Error reading/writing " + type
            sys.exit()