Coverage for DetectInstalledSites.py: 0%
133 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-28 16:41 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-28 16:41 +0000
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.
8#
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.
13#
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"""
19Attempt to detect which poker sites are installed by the user, their
20 heroname and the path to the HH files.
22This is intended for new fpdb users to get them up and running quickly.
24We assume that the majority of these users will install the poker client
25into default locations so we will only check those places.
27We just look for a hero HH folder, and don't really care if the
28 application is installed
30Situations 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
36Typical Usage:
37 See TestDetectInstalledSites.py
39Todo:
40 replace hardcoded site list with something more subtle
42"""
44import platform
45import os
46import sys
48import Configuration
50if platform.system() == 'Windows':
51 #import winpaths
52 #PROGRAM_FILES = winpaths.get_program_files()
53 #LOCAL_APPDATA = winpaths.get_local_appdata()
54 import os
55 PROGRAM_FILES = os.getenv('ProgramW6432')
56 LOCAL_APPDATA = os.getenv('APPDATA')
58class DetectInstalledSites(object):
60 def __init__(self, sitename = "All"):
62 self.Config=Configuration.Config()
63 #
64 # objects returned
65 #
66 self.sitestatusdict = {}
67 self.sitename = sitename
68 self.heroname = ""
69 self.hhpath = ""
70 self.tspath = ""
71 self.detected = ""
72 #
73 #since each site has to be hand-coded in this module, there
74 #is little advantage in querying the sites table at the moment.
75 #plus we can run from the command line as no dependencies
76 #
77 self.supportedSites = [ "Full Tilt Poker",
78 "PartyPoker",
79 "Merge",
80 "PokerStars"]#,
81 #"Everleaf",
82 #"Win2day",
83 #"OnGame",
84 #"UltimateBet",
85 #"Betfair",
86 #"Absolute",
87 #"PacificPoker",
88 #"Partouche",
89 #"PKR",
90 #"iPoker",
91 #"Winamax",
92 #"Everest" ]
94 self.supportedPlatforms = ["Linux", "XP", "Win7"]
96 if sitename == "All":
97 for siteiter in self.supportedSites:
98 self.sitestatusdict[siteiter]=self.detect(siteiter)
99 else:
100 self.sitestatusdict[sitename]=self.detect(sitename)
101 self.heroname = self.sitestatusdict[sitename]['heroname']
102 self.hhpath = self.sitestatusdict[sitename]['hhpath']
103 self.tspath = self.sitestatusdict[sitename]['tspath']
104 self.detected = self.sitestatusdict[sitename]['detected']
106 return
108 def detect(self, siteToDetect):
110 self.hhpathfound = ""
111 self.tspathfound = ""
112 self.herofound = ""
114 if siteToDetect == "Full Tilt Poker":
115 self.detectFullTilt()
116 elif siteToDetect == "PartyPoker":
117 self.detectPartyPoker()
118 elif siteToDetect == "PokerStars":
119 self.detectPokerStars()
120 elif siteToDetect == "Merge":
121 self.detectMergeNetwork()
123 if (self.hhpathfound and self.herofound):
124 encoding = sys.getfilesystemencoding()
125 if type(self.hhpathfound) is not str:
126 self.hhpathfound = str(self.hhpathfound, encoding)
127 if type(self.tspathfound) is not str:
128 self.tspathfound = str(self.tspathfound, encoding)
129 if type(self.herofound) is not str:
130 self.herofound = str(self.herofound, encoding)
131 return {"detected":True, "hhpath":self.hhpathfound, "heroname":self.herofound, "tspath":self.tspathfound}
132 else:
133 return {"detected":False, "hhpath":u"", "heroname":u"", "tspath":u""}
135 def detectFullTilt(self):
137 if self.Config.os_family == "Linux":
138 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/Full Tilt Poker/HandHistory/")
139 elif self.Config.os_family == "XP":
140 hhp=os.path.expanduser(PROGRAM_FILES+"\\Full Tilt Poker\\HandHistory\\")
141 elif self.Config.os_family == "Win7":
142 hhp=os.path.expanduser(PROGRAM_FILES+"\\Full Tilt Poker\\HandHistory\\")
143 else:
144 return
146 if os.path.exists(hhp):
147 self.hhpathfound = hhp
148 else:
149 return
151 try:
152 self.herofound = os.listdir(self.hhpathfound)[0]
153 self.hhpathfound = self.hhpathfound + self.herofound
154 except:
155 pass
157 return
159 def detectPokerStars(self):
161 if self.Config.os_family == "Linux":
162 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/PokerStars/HandHistory/")
163 tsp=os.path.expanduser("~/.wine/drive_c/Program Files/PokerStars/TournSummary/")
164 elif self.Config.os_family == "XP":
165 hhp=os.path.expanduser(PROGRAM_FILES+"\\PokerStars\\HandHistory\\")
166 tsp=os.path.expanduser(PROGRAM_FILES+"\\PokerStars\\TournSummary\\")
167 elif self.Config.os_family == "Win7":
168 hhp=os.path.expanduser(LOCAL_APPDATA+"\\PokerStars\\HandHistory\\")
169 tsp=os.path.expanduser(LOCAL_APPDATA+"\\PokerStars\\TournSummary\\")
170 elif self.Config.os_family == "Mac":
171 hhp=os.path.expanduser("~/Library/Application Support/PokerStars/HandHistory/")
172 tsp=os.path.expanduser("~/Library/Application Support/PokerStars/TournSummary/")
173 else:
174 return
176 if os.path.exists(hhp):
177 self.hhpathfound = hhp
178 if os.path.exists(tsp):
179 self.tspathfound = tsp
180 else:
181 return
183 try:
184 self.herofound = os.listdir(self.hhpathfound)[0]
185 self.hhpathfound = self.hhpathfound + self.herofound
186 if self.tspathfound:
187 self.tspathfound = self.tspathfound + self.herofound
188 except:
189 pass
191 return
193 def detectPartyPoker(self):
195 if self.Config.os_family == "Linux":
196 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/PartyGaming/PartyPoker/HandHistory/")
197 elif self.Config.os_family == "XP":
198 hhp=os.path.expanduser(PROGRAM_FILES+"\\PartyGaming\\PartyPoker\\HandHistory\\")
199 elif self.Config.os_family == "Win7":
200 hhp=os.path.expanduser("c:\\Programs\\PartyGaming\\PartyPoker\\HandHistory\\")
201 else:
202 return
204 if os.path.exists(hhp):
205 self.hhpathfound = hhp
206 else:
207 return
209 dirs = os.listdir(self.hhpathfound)
210 if "XMLHandHistory" in dirs:
211 dirs.remove("XMLHandHistory")
213 try:
214 self.herofound = dirs[0]
215 self.hhpathfound = self.hhpathfound + self.herofound
216 except:
217 pass
219 return
221 def detectMergeNetwork(self):
223# Carbon is the principal room on the Merge network but there are many other skins.
225# Normally, we understand that a player can only be valid at one
226# room on the Merge network so we will exit once successful
228# Many thanks to Ilithios for the PlayersOnly information
230 merge_skin_names = ["CarbonPoker", "PlayersOnly", "BlackChipPoker", "RPMPoker", "HeroPoker",
231 "PDCPoker", ]
233 for skin in merge_skin_names:
234 if self.Config.os_family == "Linux":
235 hhp=os.path.expanduser("~/.wine/drive_c/Program Files/"+skin+"/history/")
236 elif self.Config.os_family == "XP":
237 hhp=os.path.expanduser(PROGRAM_FILES+"\\"+skin+"\\history\\")
238 elif self.Config.os_family == "Win7":
239 hhp=os.path.expanduser(PROGRAM_FILES+"\\"+skin+"\\history\\")
240 else:
241 return
243 if os.path.exists(hhp):
244 self.hhpathfound = hhp
245 try:
246 self.herofound = os.listdir(self.hhpathfound)[0]
247 self.hhpathfound = self.hhpathfound + self.herofound
248 break
249 except:
250 continue
252 return