Don't allow the start date to be later than the end date. If it is, modify whichever...
[fpdb-dooglus.git] / pyfpdb / DetectInstalledSites.py
blob1301df344f52e2adc5e52c93458a79b7b4784e99
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2011 Gimick bbtgaf@googlemail.com
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
18 """
19 Attempt to detect which poker sites are installed by the user, their
20 heroname and the path to the HH files.
22 This is intended for new fpdb users to get them up and running quickly.
24 We assume that the majority of these users will install the poker client
25 into default locations so we will only check those places.
27 We just look for a hero HH folder, and don't really care if the
28 application is installed
30 Situations not handled are:
31 Multiple screennames using the computer
32 TODO Unexpected dirs in HH dir (e.g. "archive" may become a heroname!)
33 Non-standard installation locations
34 TODO Mac installations
36 Typical Usage:
37 See TestDetectInstalledSites.py
39 Todo:
40 replace hardcoded site list with something more subtle
42 """
43 import platform
44 import os
46 import Configuration
47 Config=Configuration.Config()
49 if Config.os_family in ['Win7', 'XP']:
50 import winpaths
51 PROGRAM_FILES = winpaths.get_program_files()
52 LOCAL_APPDATA = winpaths.get_local_appdata()
54 class DetectInstalledSites():
56 def __init__(self, sitename = "All"):
58 # objects returned
60 self.sitestatusdict = {}
61 self.sitename = sitename
62 self.heroname = ""
63 self.hhpath = ""
64 self.detected = ""
66 #since each site has to be hand-coded in this module, there
67 #is little advantage in querying the sites table at the moment.
68 #plus we can run from the command line as no dependencies
70 self.supportedSites = [ "Full Tilt Poker",
71 "PartyPoker",
72 "Carbon",
73 "PokerStars"]#,
74 #"Everleaf",
75 #"Win2day",
76 #"OnGame",
77 #"UltimateBet",
78 #"Betfair",
79 #"Absolute",
80 #"PacificPoker",
81 #"Partouche",
82 #"PKR",
83 #"iPoker",
84 #"Winamax",
85 #"Everest" ]
87 self.supportedPlatforms = ["Linux", "XP", "Win7"]
89 if sitename == "All":
90 for siteiter in self.supportedSites:
91 self.sitestatusdict[siteiter]=self.detect(siteiter)
92 else:
93 self.sitestatusdict[sitename]=self.detect(sitename)
94 self.heroname = self.sitestatusdict[sitename]['heroname']
95 self.hhpath = self.sitestatusdict[sitename]['hhpath']
96 self.detected = self.sitestatusdict[sitename]['detected']
98 return
100 def detect(self, siteToDetect):
102 self.pathfound = ""
103 self.herofound = ""
105 if siteToDetect == "Full Tilt Poker":
106 self.detectFullTilt()
107 elif siteToDetect == "PartyPoker":
108 self.detectPartyPoker()
109 elif siteToDetect == "PokerStars":
110 self.detectPokerStars()
111 elif siteToDetect == "Carbon":
112 self.detectCarbonMergeNetwork()
114 if (self.pathfound and self.herofound):
115 self.pathfound = unicode(self.pathfound)
116 self.herofound = unicode(self.herofound)
117 return {"detected":True, "hhpath":self.pathfound, "heroname":self.herofound}
118 else:
119 return {"detected":False, "hhpath":"", "heroname":""}
121 def detectFullTilt(self):
123 if Config.os_family == "Linux":
124 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/Full Tilt Poker/HandHistory/")
125 elif Config.os_family == "XP":
126 hhp=os.path.expanduser(PROGRAM_FILES+"\\Full Tilt Poker\\HandHistory\\")
127 elif Config.os_family == "Win7":
128 hhp=os.path.expanduser(PROGRAM_FILES+"\\Full Tilt Poker\\HandHistory\\")
129 else:
130 return
132 if os.path.exists(hhp):
133 self.pathfound = hhp
134 else:
135 return
137 try:
138 self.herofound = os.listdir(self.pathfound)[0]
139 self.pathfound = self.pathfound + self.herofound
140 except:
141 pass
143 return
145 def detectPokerStars(self):
147 if Config.os_family == "Linux":
148 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/PokerStars/HandHistory/")
149 elif Config.os_family == "XP":
150 hhp=os.path.expanduser(PROGRAM_FILES+"\\PokerStars\\HandHistory\\")
151 elif Config.os_family == "Win7":
152 hhp=os.path.expanduser(LOCAL_APPDATA+"\\PokerStars\\HandHistory\\")
153 else:
154 return
156 if os.path.exists(hhp):
157 self.pathfound = hhp
158 else:
159 return
161 try:
162 self.herofound = os.listdir(self.pathfound)[0]
163 self.pathfound = self.pathfound + self.herofound
164 except:
165 pass
167 return
169 def detectPartyPoker(self):
171 if Config.os_family == "Linux":
172 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/PartyGaming/PartyPoker/HandHistory/")
173 elif Config.os_family == "XP":
174 hhp=os.path.expanduser(PROGRAM_FILES+"\\PartyGaming\\PartyPoker\\HandHistory\\")
175 elif Config.os_family == "Win7":
176 hhp=os.path.expanduser("c:\\Programs\\PartyGaming\\PartyPoker\\HandHistory\\")
177 else:
178 return
180 if os.path.exists(hhp):
181 self.pathfound = hhp
182 else:
183 return
185 dirs = os.listdir(self.pathfound)
186 if "XMLHandHistory" in dirs:
187 dirs.remove("XMLHandHistory")
189 try:
190 self.herofound = dirs[0]
191 self.pathfound = self.pathfound + self.herofound
192 except:
193 pass
195 return
197 def detectCarbonMergeNetwork(self):
199 # Carbon is the principal room on the Merge network but there are many other skins.
200 # FPDB slightly confusingly uses the "Carbon" identifier for sites on the merge network
202 # Normally, we understand that a player can only be valid at one
203 # room on the Merge network so we will exit once successful
205 # Many thanks to Ilithios for the PlayersOnly information
207 merge_skin_names = ["CarbonPoker", "PlayersOnly"]
209 for skin in merge_skin_names:
210 if Config.os_family == "Linux":
211 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/"+skin+"/history/")
212 elif Config.os_family == "XP":
213 hhp=os.path.expanduser(PROGRAM_FILES+"\\"+skin+"\\history\\")
214 elif Config.os_family == "Win7":
215 hhp=os.path.expanduser(PROGRAM_FILES+"\\"+skin+"\\history\\")
216 else:
217 return
219 if os.path.exists(hhp):
220 self.pathfound = hhp
221 try:
222 self.herofound = os.listdir(self.pathfound)[0]
223 self.pathfound = self.pathfound + self.herofound
224 break
225 except:
226 continue
228 return