Update versioninfo.py
[Neo-Hockey-Test.git] / pyhockeystats / hockeyshortcuts.py
blobd562128e3c207a871d5c02e6f58599780c05c8ea
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 '''
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2015-2024 Game Maker 2k - https://github.com/GameMaker2k
14 Copyright 2015-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: hockeyshortcuts.py - Last Update: 10/17/2024 Ver. 0.9.6 RC 1 - Author: cooldude2k $
17 '''
19 from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
21 import os
22 import re
23 import sqlite3
24 import sys
25 import time
27 # Python 2 handling: Reload sys and set UTF-8 encoding if applicable
28 try:
29 reload(sys) # Only relevant for Python 2
30 if hasattr(sys, "setdefaultencoding"):
31 sys.setdefaultencoding('UTF-8')
32 except (NameError, AttributeError):
33 pass
35 # Python 3 handling: Ensure stdout and stderr use UTF-8 encoding
36 if hasattr(sys.stdout, "detach"):
37 import io
38 sys.stdout = io.TextIOWrapper(
39 sys.stdout.detach(), encoding='UTF-8', errors='replace')
40 if hasattr(sys.stderr, "detach"):
41 import io
42 sys.stderr = io.TextIOWrapper(
43 sys.stderr.detach(), encoding='UTF-8', errors='replace')
44 from .hockeyoopfuncs import *
45 from .versioninfo import (__author__, __copyright__, __credits__, __email__,
46 __license__, __license_string__, __maintainer__,
47 __program_alt_name__, __program_name__, __project__,
48 __project_release_url__, __project_url__,
49 __revision__, __revision_id__, __status__,
50 __version__, __version_alt__, __version_date__,
51 __version_date_alt__, __version_date_info__,
52 __version_date_plusrc__, __version_info__,
53 version_date, version_info)
55 try:
56 basestring
57 except NameError:
58 basestring = str
60 baseint = []
61 try:
62 baseint.append(long)
63 baseint.insert(0, int)
64 except NameError:
65 baseint.append(int)
66 baseint = tuple(baseint)
68 pickledef = None
69 try:
70 pickledef = pickle.DEFAULT_PROTOCOL
71 except AttributeError:
72 pickledef = 2
75 def MakeHockeyArrayFromHockeyDataByDict(informat="xml", **funcargs):
76 informat = informat.lower()
77 input_file_key = 'infile'
78 format_mappings = {
79 'xml': ('inxmlfile', MakeHockeyArrayFromHockeyXML),
80 'xmlalt': ('inxmlfile', MakeHockeyArrayFromHockeyXMLAlt),
81 'sgml': ('insgmlfile', MakeHockeyArrayFromHockeySGML),
82 'json': ('injsonfile', MakeHockeyArrayFromHockeyJSON),
83 'yaml': ('inyamlfile', MakeHockeyArrayFromHockeyYAML),
84 'pickle': ('inpicklefile', MakeHockeyArrayFromHockeyPickle),
85 'marshal': ('inmarshalfile', MakeHockeyArrayFromHockeyPickle),
86 'database': ('insdbfile', MakeHockeyArrayFromHockeyDatabase),
87 'olddatabase': ('insdbfile', MakeHockeyArrayFromOldHockeyDatabase),
88 'sql': ('insqlfile', MakeHockeyArrayFromHockeySQL),
89 'array': ('inhockeyarray', MakeHockeyArrayFromHockeySQLiteArray)
92 if informat in format_mappings:
93 file_key, function = format_mappings[informat]
94 if file_key and input_file_key in funcargs:
95 funcargs[file_key] = funcargs.pop(input_file_key)
96 return function(**funcargs)
97 return False
99 def MakeHockeyArrayFromHockeyDataByList(informat="xml", *funcargs):
100 format_mappings = {
101 'xml': MakeHockeyArrayFromHockeyXML,
102 'xmlalt': MakeHockeyArrayFromHockeyXMLAlt,
103 'sgml': MakeHockeyArrayFromHockeySGML,
104 'json': MakeHockeyArrayFromHockeyJSON,
105 'yaml': MakeHockeyArrayFromHockeyYAML,
106 'pickle': MakeHockeyArrayFromHockeyPickle,
107 'marshal': MakeHockeyArrayFromHockeyPickle,
108 'database': MakeHockeyArrayFromHockeyDatabase,
109 'olddatabase': MakeHockeyArrayFromOldHockeyDatabase,
110 'sql': MakeHockeyArrayFromHockeySQL,
111 'array': MakeHockeyArrayFromHockeySQLiteArray
113 return format_mappings.get(informat.lower(), lambda *args: False)(*funcargs)
115 def MakeHockeyArrayFromHockeyData(funcargs):
116 if isinstance(funcargs, (tuple, list)):
117 return MakeHockeyArrayFromHockeyDataByList(*funcargs)
118 elif isinstance(funcargs, dict):
119 return MakeHockeyArrayFromHockeyDataByDict(**funcargs)
120 return False
122 def MakeHockeyDataFromHockeyArrayByDict(outformat="xml", **funcargs):
123 outformat = outformat.lower()
124 format_mappings = {
125 'xml': MakeHockeyXMLFromHockeyArray,
126 'xmlalt': MakeHockeyXMLAltFromHockeyArray,
127 'sgml': MakeHockeySGMLFromHockeyArray,
128 'json': MakeHockeyJSONFromHockeyArray,
129 'yaml': MakeHockeyYAMLFromHockeyArray,
130 'pickle': MakeHockeyPickleFromHockeyArray,
131 'marshal': MakeHockeyMarshalFromHockeyArray,
132 'database': MakeHockeyDatabaseFromHockeyArray,
133 'py': MakeHockeyPythonFromHockeyArray,
134 'pyalt': MakeHockeyPythonAltFromHockeyArray,
135 'pyoop': MakeHockeyPythonOOPFromHockeyArray,
136 'pyoopalt': MakeHockeyPythonOOPAltFromHockeyArray,
137 'sql': MakeHockeySQLFromHockeyArray,
138 'array': MakeHockeySQLiteArrayFromHockeyArray
140 return format_mappings.get(outformat, lambda **kwargs: False)(**funcargs)
142 def MakeHockeyDataFromHockeyArrayByList(outformat="xml", *funcargs):
143 format_mappings = {
144 'xml': MakeHockeyXMLFromHockeyArray,
145 'xmlalt': MakeHockeyXMLAltFromHockeyArray,
146 'sgml': MakeHockeySGMLFromHockeyArray,
147 'json': MakeHockeyJSONFromHockeyArray,
148 'yaml': MakeHockeyYAMLFromHockeyArray,
149 'pickle': MakeHockeyPickleFromHockeyArray,
150 'marshal': MakeHockeyMarshalFromHockeyArray,
151 'database': MakeHockeyDatabaseFromHockeyArray,
152 'py': MakeHockeyPythonFromHockeyArray,
153 'pyalt': MakeHockeyPythonAltFromHockeyArray,
154 'pyoop': MakeHockeyPythonOOPFromHockeyArray,
155 'pyoopalt': MakeHockeyPythonOOPAltFromHockeyArray,
156 'sql': MakeHockeySQLFromHockeyArray,
157 'array': MakeHockeySQLiteArrayFromHockeyArray
159 return format_mappings.get(outformat.lower(), lambda *args: False)(*funcargs)
161 def MakeHockeyDataFromHockeyArray(funcargs):
162 if isinstance(funcargs, (tuple, list)):
163 return MakeHockeyDataFromHockeyArrayByList(*funcargs)
164 elif isinstance(funcargs, dict):
165 return MakeHockeyDataFromHockeyArrayByDict(**funcargs)
166 return False
168 def MakeHockeyDataFileFromHockeyArrayByDict(outformat="xml", **funcargs):
169 outformat = outformat.lower()
170 file_format_mappings = {
171 'xml': ('outxmlfile', MakeHockeyXMLFileFromHockeyArray),
172 'xmlalt': ('outxmlfile', MakeHockeyXMLAltFileFromHockeyArray),
173 'sgml': ('outsgmlfile', MakeHockeySGMLFileFromHockeyArray),
174 'json': ('outjsonfile', MakeHockeyJSONFileFromHockeyArray),
175 'yaml': ('outyamlfile', MakeHockeyYAMLFileFromHockeyArray),
176 'pickle': ('outpicklefile', MakeHockeyPickleFileFromHockeyArray),
177 'marshal': ('outmarshalfile', MakeHockeyMarshalFileFromHockeyArray),
178 'py': ('outpyfile', MakeHockeyPythonFileFromHockeyArray),
179 'pyalt': ('outpyfile', MakeHockeyPythonAltFileFromHockeyArray),
180 'pyoop': ('outpyfile', MakeHockeyPythonOOPFileFromHockeyArray),
181 'pyoopalt': ('outpyfile', MakeHockeyPythonOOPAltFileFromHockeyArray),
182 'sql': ('outsqlfile', MakeHockeySQLFileFromHockeyArray)
185 if outformat in file_format_mappings:
186 file_key, function = file_format_mappings[outformat]
187 if file_key in funcargs and 'outfile' in funcargs:
188 funcargs[file_key] = funcargs.pop('outfile')
189 return function(**funcargs)
190 return False
192 def MakeHockeyDataFileFromHockeyArrayByList(outformat="xml", *funcargs):
193 file_format_mappings = {
194 'xml': MakeHockeyXMLFileFromHockeyArray,
195 'xmlalt': MakeHockeyXMLAltFileFromHockeyArray,
196 'sgml': MakeHockeySGMLFileFromHockeyArray,
197 'json': MakeHockeyJSONFileFromHockeyArray,
198 'yaml': MakeHockeyYAMLFileFromHockeyArray,
199 'pickle': MakeHockeyPickleFileFromHockeyArray,
200 'marshal': MakeHockeyMarshalFileFromHockeyArray,
201 'py': MakeHockeyPythonFileFromHockeyArray,
202 'pyalt': MakeHockeyPythonAltFileFromHockeyArray,
203 'pyoop': MakeHockeyPythonOOPFileFromHockeyArray,
204 'pyoopalt': MakeHockeyPythonOOPAltFileFromHockeyArray,
205 'sql': MakeHockeySQLFileFromHockeyArray
207 return file_format_mappings.get(outformat.lower(), lambda *args: False)(*funcargs)
209 def MakeHockeyDataFileFromHockeyArray(funcargs):
210 if isinstance(funcargs, (tuple, list)):
211 return MakeHockeyDataFileFromHockeyArrayByList(*funcargs)
212 elif isinstance(funcargs, dict):
213 return MakeHockeyDataFileFromHockeyArrayByDict(**funcargs)
214 return False
216 def MakeHockeySQLiteArrayFromHockeySQLiteDataByDict(informat="xml", **funcargs):
217 informat = informat.lower()
218 file_format_mappings = {
219 'xml': ('inxmlfile', MakeHockeySQLiteArrayFromHockeySQLiteXML),
220 'xmlalt': ('inxmlfile', MakeHockeySQLiteArrayFromHockeySQLiteXMLAlt),
221 'sgml': ('insgmlfile', MakeHockeySQLiteArrayFromHockeySQLiteSGML),
222 'json': ('injsonfile', MakeHockeySQLiteArrayFromHockeySQLiteJSON),
223 'yaml': ('inyamlfile', MakeHockeySQLiteArrayFromHockeySQLiteYAML),
224 'pickle': ('inpicklefile', MakeHockeySQLiteArrayFromHockeySQLitePickle),
225 'marshal': ('inmarshalfile', MakeHockeySQLiteArrayFromHockeySQLitePickle),
226 'database': ('insdbfile', MakeHockeySQLiteArrayFromHockeyDatabase),
227 'olddatabase': ('insdbfile', MakeHockeySQLiteArrayFromOldHockeyDatabase),
228 'sql': ('insqlfile', MakeHockeySQLiteArrayFromHockeySQL),
229 'array': ('inhockeyarray', MakeHockeySQLiteArrayFromHockeyArray)
232 if informat in file_format_mappings:
233 file_key, function = file_format_mappings[informat]
234 if file_key in funcargs and 'infile' in funcargs:
235 funcargs[file_key] = funcargs.pop('infile')
236 return function(**funcargs)
237 return False
239 def MakeHockeySQLiteArrayFromHockeySQLiteDataByList(informat="xml", *funcargs):
240 format_mappings = {
241 'xml': MakeHockeySQLiteArrayFromHockeySQLiteXML,
242 'xmlalt': MakeHockeySQLiteArrayFromHockeySQLiteXMLAlt,
243 'sgml': MakeHockeySQLiteArrayFromHockeySQLiteSGML,
244 'json': MakeHockeySQLiteArrayFromHockeySQLiteJSON,
245 'yaml': MakeHockeySQLiteArrayFromHockeySQLiteYAML,
246 'pickle': MakeHockeySQLiteArrayFromHockeySQLitePickle,
247 'marshal': MakeHockeySQLiteArrayFromHockeySQLitePickle,
248 'database': MakeHockeySQLiteArrayFromHockeyDatabase,
249 'olddatabase': MakeHockeySQLiteArrayFromOldHockeyDatabase,
250 'sql': MakeHockeySQLiteArrayFromHockeySQL,
251 'array': MakeHockeySQLiteArrayFromHockeyArray
253 return format_mappings.get(informat.lower(), lambda *args: False)(*funcargs)
255 def MakeHockeySQLiteArrayFromHockeySQLiteData(funcargs):
256 if isinstance(funcargs, (tuple, list)):
257 return MakeHockeySQLiteArrayFromHockeySQLiteDataByList(*funcargs)
258 elif isinstance(funcargs, dict):
259 return MakeHockeySQLiteArrayFromHockeySQLiteDataByDict(**funcargs)
260 return False
262 def MakeHockeySQLiteDataFileFromHockeySQLiteArrayByDict(outformat="xml", **funcargs):
263 outformat = outformat.lower()
264 file_format_mappings = {
265 'xml': ('outxmlfile', MakeHockeySQLiteXMLFileFromHockeySQLiteArray),
266 'xmlalt': ('outxmlfile', MakeHockeySQLiteXMLAltFileFromHockeySQLiteArray),
267 'sgml': ('outsgmlfile', MakeHockeySQLiteSGMLFileFromHockeySQLiteArray),
268 'json': ('outjsonfile', MakeHockeySQLiteJSONFileFromHockeySQLiteArray),
269 'yaml': ('outyamlfile', MakeHockeySQLiteYAMLFileFromHockeySQLiteArray),
270 'pickle': ('outpicklefile', MakeHockeySQLitePickleFileFromHockeySQLiteArray),
271 'marshal': ('outmarshalfile', MakeHockeySQLiteMarshalFileFromHockeySQLiteArray),
272 'py': ('outpyfile', MakeHockeyPythonFileFromHockeySQLiteArray),
273 'pyalt': ('outpyfile', MakeHockeyPythonAltFileFromHockeySQLiteArray),
274 'pyoop': ('outpyfile', MakeHockeyPythonOOPFileFromHockeySQLiteArray),
275 'pyoopalt': ('outpyfile', MakeHockeyPythonOOPAltFileFromHockeySQLiteArray),
276 'sql': ('outsqlfile', MakeHockeySQLFileFromHockeySQLiteArray)
279 if outformat in file_format_mappings:
280 file_key, function = file_format_mappings[outformat]
281 if file_key in funcargs and 'outfile' in funcargs:
282 funcargs[file_key] = funcargs.pop('outfile')
283 return function(**funcargs)
284 return False
286 def MakeHockeySQLiteDataFileFromHockeySQLiteArrayByList(outformat="xml", *funcargs):
287 file_format_mappings = {
288 'xml': MakeHockeySQLiteXMLFileFromHockeySQLiteArray,
289 'xmlalt': MakeHockeySQLiteXMLAltFileFromHockeySQLiteArray,
290 'sgml': MakeHockeySQLiteSGMLFileFromHockeySQLiteArray,
291 'json': MakeHockeySQLiteJSONFileFromHockeySQLiteArray,
292 'yaml': MakeHockeySQLiteYAMLFileFromHockeySQLiteArray,
293 'pickle': MakeHockeySQLitePickleFileFromHockeySQLiteArray,
294 'marshal': MakeHockeySQLiteMarshalFileFromHockeySQLiteArray,
295 'py': MakeHockeyPythonFileFromHockeySQLiteArray,
296 'pyalt': MakeHockeyPythonAltFileFromHockeySQLiteArray,
297 'pyoop': MakeHockeyPythonOOPFileFromHockeySQLiteArray,
298 'pyoopalt': MakeHockeyPythonOOPAltFileFromHockeySQLiteArray,
299 'sql': MakeHockeySQLFileFromHockeySQLiteArray
301 return file_format_mappings.get(outformat.lower(), lambda *args: False)(*funcargs)
303 def MakeHockeySQLiteDataFileFromHockeySQLiteArray(funcargs):
304 if isinstance(funcargs, (tuple, list)):
305 return MakeHockeySQLiteDataFileFromHockeySQLiteArrayByList(*funcargs)
306 elif isinstance(funcargs, dict):
307 return MakeHockeySQLiteDataFileFromHockeySQLiteArrayByDict(**funcargs)
308 return False