Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

main module

  • Loading branch information...
commit bd8f2dd3ea11fe252ae8d9e7b3acbb5b210f7915 1 parent c2e3893
@KonishchevDmitry authored
Showing with 51 additions and 0 deletions.
  1. +51 −0 main.py
View
51 main.py
@@ -0,0 +1,51 @@
+"""Contains various functions for script bootstrapping."""
+
+import locale
+import platform
+
+import pycl.main
+
+_ENCODING = None
+"""Cache of current locale's encoding."""
+
+
+def get_locale_encoding(cache = False):
+ """Returns current locale's encoding."""
+
+ global _ENCODING
+
+ if cache and _ENCODING is not None:
+ return _ENCODING
+
+ try:
+ _ENCODING = locale.getlocale()[1]
+
+ if _ENCODING is None:
+ _ENCODING = "UTF-8"
+ except ValueError:
+ if pycl.main.is_osx():
+ # There are some bugs in OS X locale settings, so just force using
+ # UTF-8 encoding on errors.
+ _ENCODING = "UTF-8"
+
+ raise
+
+ return _ENCODING
+
+
+def is_osx():
+ """Returns True if we are running under OS X."""
+
+ return platform.system() == "Darwin"
+
+
+def set_environment():
+ """Prepares the script's environment."""
+
+ pycl.main.set_locale()
+
+
+def set_locale():
+ """Sets current locale from environment."""
+
+ locale.setlocale(locale.LC_ALL, "")
Please sign in to comment.
Something went wrong with that request. Please try again.