PEP8: Fix whitespace
[openblackhole/openblackhole-enigma2.git] / tools / host_tools / FormatConverter / datasource.py
1 from input import inputChoices
2
3 class datasource:
4         def __init__(self):
5                 self.clear()
6
7         def setDatasources(self, datasources):
8                 self.datasources = datasources
9
10         def getCapabilities(self):
11                 return []
12
13         def getName(self):
14                 return "N/A"
15
16         def getStatus(self):
17                 text = str(len(self.transponderlist.keys())) + " Satellites" + "\n"
18                 return text
19
20         def printAll(self):
21                 for sat in self.transponderlist.keys():
22                         print "***********"
23                         print "sat:", sat, self.satnames[sat]
24                         for transponder in self.transponderlist[sat]:
25                                 print transponder
26
27         def clear(self):
28                 self.transponderlist = {}
29                 self.satnames = {}
30
31         def read(self):
32                 pass
33
34         def write(self):
35                 pass
36
37         def addSat(self, satname, satpos):
38                 if not self.transponderlist.has_key(satpos):
39                         self.transponderlist[satpos] = []
40                         self.satnames[satpos] = satname
41
42         def addTransponder(self, satpos, transponder):
43                 if len(transponder.keys()) >= 6:
44                         self.transponderlist[satpos].append(transponder)
45
46 class genericdatasource(datasource):
47         def __init__(self):
48                 datasource.__init__(self)
49                 self.source = self.destination = None
50
51         def getName(self):
52                 return "Generic Datasource"
53
54         def getCapabilities(self):
55                 return [("copy data from one source to another", self.copy), ("merge data from one source into another", self.merge)]
56
57         def copy(self):
58                 self.copymerge(action = "copy")
59
60         def merge(self):
61                 self.copymerge(action = "merge")
62
63         def copymerge(self, action = "copy"):
64                 choice = -1
65                 while choice is not None:
66                         choice = inputChoices(["select source", "select destination", "copy now!"])
67                         if choice == 0:
68                                 print "\nselect source:"
69                                 self.source = self.selectDatasource()
70                         elif choice == 1:
71                                 print "\nselect destination"
72                                 self.destination = self.selectDatasource()
73                         elif choice == 2:
74                                 self.docopymerge(action)
75
76         def docopymerge(self, action = "copy"):
77                 if self.source is None:
78                         print "select a source first!"
79                 elif self.destination is None:
80                         print "select a destination first!"
81                 else:
82                         if action == "copy":
83                                 print "copying ",
84                         elif action == "merge":
85                                 print "merging ",
86                         print "from %s to %s" % (self.source.getName(), self.destination.getName())
87                         countsat = 0
88                         counttransponder = 0
89                         if action == "copy":
90                                 self.destination.clear()
91                         for satpos in self.source.transponderlist.keys():
92                                 countsat += 1
93                                 self.destination.addSat(self.source.satnames[satpos], satpos)
94                                 for transponder in self.source.transponderlist[satpos]:
95                                         counttransponder += 1
96                                         self.destination.addTransponder(satpos, transponder)
97                         print "copied %d sats with %d transponders" % (countsat, counttransponder)
98
99         def selectDatasource(self):
100                 list = []
101                 sources = []
102                 for source in self.datasources:
103                         if source != self:
104                                 list.append(source.getName() + (" (%d sats)" % len(source.transponderlist.keys())))
105                                 sources.append(source)
106                 choice = inputChoices(list)
107                 if choice is None:
108                         return None
109                 return sources[choice]