Coverage for DetectInstalledSites.py: 0%
156 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +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
49import logging
51log = logging.getLogger("config")
53if platform.system() == "Windows":
54 # import winpaths
55 # PROGRAM_FILES = winpaths.get_program_files()
56 # LOCAL_APPDATA = winpaths.get_local_appdata()
57 import os
59 PROGRAM_FILES = os.getenv("ProgramW6432")
60 LOCAL_APPDATA = os.getenv("APPDATA")
63class DetectInstalledSites(object):
64 def __init__(self, sitename="All"):
65 self.Config = Configuration.Config()
66 #
67 # objects returned
68 #
69 self.sitestatusdict = {}
70 self.sitename = sitename
71 self.heroname = ""
72 self.hhpath = ""
73 self.tspath = ""
74 self.detected = ""
75 #
76 # since each site has to be hand-coded in this module, there
77 # is little advantage in querying the sites table at the moment.
78 # plus we can run from the command line as no dependencies
79 #
80 self.supportedSites = ["Full Tilt Poker", "PartyPoker", "Merge", "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):
109 self.hhpathfound = ""
110 self.tspathfound = ""
111 self.herofound = ""
113 if siteToDetect == "Full Tilt Poker":
114 self.detectFullTilt()
115 elif siteToDetect == "PartyPoker":
116 self.detectPartyPoker()
117 elif siteToDetect == "PokerStars":
118 self.detectPokerStars()
119 elif siteToDetect == "Merge":
120 self.detectMergeNetwork()
122 if self.hhpathfound and self.herofound:
123 encoding = sys.getfilesystemencoding()
124 if type(self.hhpathfound) is not str:
125 self.hhpathfound = str(self.hhpathfound, encoding)
126 if type(self.tspathfound) is not str:
127 self.tspathfound = str(self.tspathfound, encoding)
128 if type(self.herofound) is not str:
129 self.herofound = str(self.herofound, encoding)
130 return {
131 "detected": True,
132 "hhpath": self.hhpathfound,
133 "heroname": self.herofound,
134 "tspath": self.tspathfound,
135 }
136 else:
137 return {"detected": False, "hhpath": "", "heroname": "", "tspath": ""}
139 def detectFullTilt(self):
140 if self.Config.os_family == "Linux":
141 hhp = os.path.expanduser("~/.wine/drive_c/Program Files/Full Tilt Poker/HandHistory/")
142 elif self.Config.os_family in ["XP", "Win7"]:
143 hhp = os.path.expanduser(os.path.join(PROGRAM_FILES, "Full Tilt Poker", "HandHistory"))
144 else:
145 return
147 if os.path.exists(hhp):
148 self.hhpathfound = hhp
149 else:
150 return
152 try:
153 files = os.listdir(self.hhpathfound)
154 if files:
155 self.herofound = files[0]
156 self.hhpathfound = os.path.join(self.hhpathfound, self.herofound)
157 except FileNotFoundError:
158 # The HandHistory directory does not exist or is not accessible
159 self.herofound = None
160 except IndexError:
161 # No files in the HandHistory directory
162 self.herofound = None
163 except Exception as e:
164 # Generic management for any other unforeseen exceptions (logging, debugging, etc.)
165 log.error(f"An unexpected error has occurred : {e}")
166 self.herofound = None
168 return
170 def detectPokerStars(self):
171 if self.Config.os_family == "Linux":
172 hhp = os.path.expanduser("~/.wine/drive_c/Program Files/PokerStars/HandHistory/")
173 tsp = os.path.expanduser("~/.wine/drive_c/Program Files/PokerStars/TournSummary/")
174 elif self.Config.os_family == "XP":
175 hhp = os.path.expanduser(os.path.join(PROGRAM_FILES, "PokerStars", "HandHistory"))
176 tsp = os.path.expanduser(os.path.join(PROGRAM_FILES, "PokerStars", "TournSummary"))
177 elif self.Config.os_family == "Win7":
178 hhp = os.path.expanduser(os.path.join(LOCAL_APPDATA, "PokerStars", "HandHistory"))
179 tsp = os.path.expanduser(os.path.join(LOCAL_APPDATA, "PokerStars", "TournSummary"))
180 elif self.Config.os_family == "Mac":
181 hhp = os.path.expanduser("~/Library/Application Support/PokerStars/HandHistory/")
182 tsp = os.path.expanduser("~/Library/Application Support/PokerStars/TournSummary/")
183 else:
184 return
186 if os.path.exists(hhp):
187 self.hhpathfound = hhp
188 if os.path.exists(tsp):
189 self.tspathfound = tsp
190 else:
191 return
193 try:
194 files = os.listdir(self.hhpathfound)
195 if files:
196 self.herofound = files[0]
197 self.hhpathfound = os.path.join(self.hhpathfound, self.herofound)
198 if self.tspathfound:
199 self.tspathfound = os.path.join(self.tspathfound, self.herofound)
200 except FileNotFoundError:
201 self.herofound = None
202 except IndexError:
203 self.herofound = None
204 except Exception as e:
205 log.error(f"An unexpected error has occurred : {e}")
206 self.herofound = None
208 return
210 def detectPartyPoker(self):
211 if self.Config.os_family == "Linux":
212 hhp = os.path.expanduser("~/.wine/drive_c/Program Files/PartyGaming/PartyPoker/HandHistory/")
213 elif self.Config.os_family == "XP":
214 hhp = os.path.expanduser(os.path.join(PROGRAM_FILES, "PartyGaming", "PartyPoker", "HandHistory"))
215 elif self.Config.os_family == "Win7":
216 hhp = os.path.expanduser("c:\\Programs\\PartyGaming\\PartyPoker\\HandHistory\\")
217 else:
218 return
220 if os.path.exists(hhp):
221 self.hhpathfound = hhp
222 else:
223 return
225 dirs = os.listdir(self.hhpathfound)
226 if "XMLHandHistory" in dirs:
227 dirs.remove("XMLHandHistory")
229 try:
230 if dirs:
231 self.herofound = dirs[0]
232 self.hhpathfound = os.path.join(self.hhpathfound, self.herofound)
233 except IndexError:
234 self.herofound = None
235 except Exception as e:
236 log.error(f"An unexpected error has occurred : {e}")
237 self.herofound = None
239 return
241 def detectMergeNetwork(self):
242 # Carbon is the principal room on the Merge network but there are many other skins.
244 # Normally, we understand that a player can only be valid at one
245 # room on the Merge network so we will exit once successful
247 # Many thanks to Ilithios for the PlayersOnly information
249 merge_skin_names = [
250 "CarbonPoker",
251 "PlayersOnly",
252 "BlackChipPoker",
253 "RPMPoker",
254 "HeroPoker",
255 "PDCPoker",
256 ]
258 for skin in merge_skin_names:
259 if self.Config.os_family == "Linux":
260 hhp = os.path.expanduser("~/.wine/drive_c/Program Files/" + skin + "/history/")
261 elif self.Config.os_family in ["XP", "Win7"]:
262 hhp = os.path.expanduser(os.path.join(PROGRAM_FILES, skin, "history"))
263 else:
264 return
266 if os.path.exists(hhp):
267 self.hhpathfound = hhp
268 try:
269 files = os.listdir(self.hhpathfound)
270 if files:
271 self.herofound = files[0]
272 self.hhpathfound = os.path.join(self.hhpathfound, self.herofound)
273 break
274 except FileNotFoundError:
275 self.herofound = None
276 except IndexError:
277 self.herofound = None
278 except Exception as e:
279 log.error(f"An unexpected error has occurred : {e}")
280 self.herofound = None
282 return