Module pytson
[hide private]
[frames] | no frames]

Source Code for Module pytson

  1  import os 
  2  import shutil 
  3  import platform 
  4  import glob 
  5  import re 
  6   
  7  import ts3lib 
  8   
  9  from PythonQt.QtGui import QApplication 
 10   
 11   
 12  _PYTSON_VERSION = "1.2.2" 
13 14 15 -def tr(context, sourcetext, disambiguation="", n=-1):
16 """ 17 Returns the current translation for a string. This function calls can be 18 extracted by pyTSon's pylupdate.py. 19 @param context: context of the string literal, must be a raw string, not 20 the return value of another function, an attribute or such 21 @type context: str 22 @param sourcetext: translatable string, must be a raw string, not the 23 return value of another function, an attribute or such 24 @type sourcetext: str 25 @param disambiguation: used to distinguish between two equal sourcetexts 26 int the same context, or as comment, optional, defaults to an empty string, 27 must be a raw string, not the return value of another function, an 28 attribute or such 29 @type disambiguation: str 30 @param n: used for strings containing plurals, optional, defaults to -1 31 @type n: int 32 """ 33 return QApplication.translate(context, sourcetext, disambiguation, n)
34
35 36 -class Translatable(object):
37 """ 38 Baseclass for a class using translatable string literals. 39 """ 40 @classmethod
41 - def _tr(cls, sourcetext, disambiguation="", n=-1, context=None):
42 """ 43 Returns the current translation for a string. This method calls can be 44 extracted by pyTSon's pylupdate.py. 45 @param sourcetext: translatable string, must be a raw string, not the 46 return value of another function, an attribute or such 47 @type sourcetext: str 48 @param disambiguation: used to distinguish between two equal 49 sourcetexts int the same context, or as comment, optional, defaults 50 to an empty string, must be a raw string, not the return value of 51 another function, an attribute or such 52 @type disambiguation: str 53 @param n: used for strings containing plurals, optional, defaults to -1 54 @type n: int 55 @param context: context to use for the string, optional, if set to 56 None, the classname is used as context, defaults to None 57 @type context: str 58 """ 59 if not context: 60 return tr(cls.__name__, sourcetext, disambiguation=disambiguation, 61 n=n) 62 else: 63 return tr(context, sourcetext, disambiguation=disambiguation, n=n)
64
65 66 -def locales():
67 """ 68 Generator function to return all locale codes available for translation 69 in format language_country (see ISO 639 and ISO 3166) 70 @return: Generator function to return the language codes 71 @rtype: Generator[str] 72 """ 73 for f in glob.glob(getPluginPath("ressources", "i18n", "pyTSon-*.qm")): 74 m = re.match(r'^pyTSon-(\w\w_\w\w).qm$', os.path.split(f)[-1]) 75 if m: 76 yield m.group(1)
77
78 79 -def getConfigPath(*args):
80 """ 81 Returns pyTSon's configpath, that is, the subdirectory 'pyTSon' in the 82 TeamSpeak 3 config directory. 83 @param args: path fields joined to the result as list of strings 84 @type args: list[str] 85 @return: The accumulated path 86 @rtype: str 87 """ 88 return os.path.join(ts3lib.getConfigPath(), "pyTSon", *args)
89
90 91 -def getPluginPath(*args):
92 """ 93 Returns pyTSon's pluginpath, that is, the subdirectory 'pyTSon' in the 94 TeamSpeak 3 plugins directory. 95 @param args: path fields joined to the result as list of strings 96 @type args: list[str] 97 @return: The accumulated path 98 @rtype: str 99 """ 100 return os.path.join(ts3lib.getPluginPath(), "pyTSon", *args)
101
102 103 -def _setup():
104 """ 105 Sets up pyTSon's infrastructure. 106 """ 107 if not os.path.isdir(getConfigPath()): 108 os.mkdir(getConfigPath()) 109 110 respath = getPluginPath("ressources", "repositorymaster.json") 111 confpath = getConfigPath("repositorymaster.json") 112 if not os.path.exists(confpath): 113 shutil.copy(respath, confpath) 114 115 with open(getPluginPath("VERSION"), "r") as f: 116 global _PYTSON_VERSION 117 _PYTSON_VERSION = f.readline().strip()
118
119 120 -def platformstr():
121 """ 122 Returns the platform pyTSon is currently running on. 123 @return: the platform (and architecture) string 124 @rtype: str 125 """ 126 if platform.system() == "Mac": 127 return "Mac" 128 else: 129 return "%s-%s" % (platform.system(), platform.architecture()[0])
130
131 132 -def getVersion():
133 """ 134 Returns the current version of pyTSon. 135 @return: the version as string 136 @rtype: str 137 """ 138 return _PYTSON_VERSION
139
140 141 -def getCurrentApiVersion():
142 """ 143 Returns the current apiversion of the ts3 plugin sdk. This should not be 144 used in ts3plugin.apiVersion. Be fair and update your plugin manually! 145 @return: the apiVersion 146 @rtype: str 147 """ 148 return 21
149