Last active
April 6, 2018 19:32
-
-
Save juancarlospaco/96980b12db4b20c413d3 to your computer and use it in GitHub Desktop.
Debug Encoding and Check for root.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import sys, os | |
import logging as log | |
from getpass import getuser | |
from platform import platform, python_version | |
def make_root_check_and_encoding_debug(): | |
"""Debug and Log Encodings and Check for root/administrator,return Boolean. | |
>>> make_root_check_and_encoding_debug() | |
True | |
""" | |
log.info(__doc__) | |
log.debug("Python {0} on {1}.".format(python_version(), platform())) | |
log.debug("STDIN Encoding: {0}.".format(sys.stdin.encoding)) | |
log.debug("STDERR Encoding: {0}.".format(sys.stderr.encoding)) | |
log.debug("STDOUT Encoding:{}".format(getattr(sys.stdout, "encoding", ""))) | |
log.debug("Default Encoding: {0}.".format(sys.getdefaultencoding())) | |
log.debug("FileSystem Encoding: {0}.".format(sys.getfilesystemencoding())) | |
log.debug("PYTHONIOENCODING Encoding: {0}.".format( | |
os.environ.get("PYTHONIOENCODING", None))) | |
os.environ["PYTHONIOENCODING"] = "utf-8" | |
sys.dont_write_bytecode = True | |
if not sys.platform.startswith("win"): # root check | |
if not os.geteuid(): | |
log.critical("Runing as root is not Recommended,NOT Run as root!.") | |
return False | |
elif sys.platform.startswith("win"): # administrator check | |
if getuser().lower().startswith("admin"): | |
log.critical("Runing as Administrator is not Recommended!.") | |
return False | |
return True | |
if __name__ in '__main__': | |
log.basicConfig(level=-1) # basic logger | |
make_root_check_and_encoding_debug() | |
__import__("doctest").testmod(verbose=True, report=True, exclude_empty=1) |
Author
juancarlospaco
commented
Jun 19, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment