# Path: utils/settings/_settings.py
# _DEFAULT=object() # unique object to compare identity with
# class EmptyMapping(Mapping):
# class ImmutableMapping(Mapping):
# class EmptySection(EmptyMapping):
# class SettingsSection(ImmutableMapping):
# class Settings(object):
#   def __init__(self,default=None):
#   def __getitem__(self,key):
#   def __len__(self):
#   def __iter__(self):
#   def __contains__(self,key):
#   def get(self, key, default=_DEFAULT):
#   def __str__(self):
#   def __repr__(self):
#   def __init__(self,_dict,default=None):
#   def __getitem__(self,key):
#   def __len__(self):
#   def __iter__(self):
#   def __contains__(self,key):
#   def get(self, key, default=_DEFAULT):
#   def __str__(self):
#   def __repr__(self):
#   def __init__(self):
#   def sections(self):
#   def getsection(self,key,**kwargs):
#   def __eq__(self,other):
#   def __str__(self):
#   def __repr__(self):
#   def __init__(self,sections,values):
#   def sections(self):
#   def getsection(self,key,**kwargs):
#   def __getattr__(self,name):
#   def __eq__(self,other):
#   def __str__(self):
#   def __repr__(self):
# def _mergesettings(parent,sectiondict,section,value):
# def _loadsettings(filename,parent=None):
# def __print(section,indent=""):
#   def __new__(cls):
#   def system(self):
#   def user(self):
#   def get(self,user):
# 
# Path: downloadermodules/url.py
# def download(path,args):
#     url,targetname,*args=args
#     targetname=os.path.join(path,targetname)
#     decompress=None
#     if len(args)>1:
#         raise DownloaderError("Too many arguments")
#     elif len(args)==1:
#         decompress=args[0]
#         if decompress not in ["zip","tar","gz","tgz","tar.gz"]:
#             raise DownloaderError("Unknown decompression type")
#         if decompress in ["gz"]: # compression without filenames
#             targetname+="."+decompress
#     try:
#         fname,headers=urllib.request.urlretrieve(url,filename=targetname,reporthook=reporthook)
#     except urllib.error.URLError as ex:
#         print("Error downloading "+str(targetname)+": "+ex.reason)
#         raise DownloaderError("Can't download file")
#     if decompress == "zip":
#         ret=sp.call(["unzip",targetname,"-d",path],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")
#     elif decompress == "tar" or decompress == "tar.gz":
#         ret=sp.call(["tar","-xf",targetname,"-C",path],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")
#     elif decompress == "tgz":
#         ret=sp.call(["tar","-xfz",targetname,"-C",path],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")
#     elif decompress == "gz":
#         ret=sp.call(["gunzip",targetname],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")


from utils.settings import settings 
from downloadermodules.url import download as url_download
import pwd
import os
import os.path
import subprocess as sp


# if a user has already installed steam to e.g ubuntu, steamcmd prefers to be installed in the same directory (or at least when steamcmd starts, it sends the error related things there as if it wants to be installed there.
STEAMCMD_DIR = os.path.expanduser(settings.user.downloader.getsection('steamcmd').get('steamcmd_path') or "~/.local/share/Steam/" if os.path.isdir(os.path.expanduser("~/.local/share/Steam/")) else "~/Steam/")
STEAMCMD_EXE = STEAMCMD_DIR + "steamcmd.sh"
STEAMCMD_URL = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz"

# Path: utils/settings/_settings.py
# _DEFAULT=object() # unique object to compare identity with
# class EmptyMapping(Mapping):
# class ImmutableMapping(Mapping):
# class EmptySection(EmptyMapping):
# class SettingsSection(ImmutableMapping):
# class Settings(object):
#   def __init__(self,default=None):
#   def __getitem__(self,key):
#   def __len__(self):
#   def __iter__(self):
#   def __contains__(self,key):
#   def get(self, key, default=_DEFAULT):
#   def __str__(self):
#   def __repr__(self):
#   def __init__(self,_dict,default=None):
#   def __getitem__(self,key):
#   def __len__(self):
#   def __iter__(self):
#   def __contains__(self,key):
#   def get(self, key, default=_DEFAULT):
#   def __str__(self):
#   def __repr__(self):
#   def __init__(self):
#   def sections(self):
#   def getsection(self,key,**kwargs):
#   def __eq__(self,other):
#   def __str__(self):
#   def __repr__(self):
#   def __init__(self,sections,values):
#   def sections(self):
#   def getsection(self,key,**kwargs):
#   def __getattr__(self,name):
#   def __eq__(self,other):
#   def __str__(self):
#   def __repr__(self):
# def _mergesettings(parent,sectiondict,section,value):
# def _loadsettings(filename,parent=None):
# def __print(section,indent=""):
#   def __new__(cls):
#   def system(self):
#   def user(self):
#   def get(self,user):
# 
# Path: downloadermodules/url.py
# def download(path,args):
#     url,targetname,*args=args
#     targetname=os.path.join(path,targetname)
#     decompress=None
#     if len(args)>1:
#         raise DownloaderError("Too many arguments")
#     elif len(args)==1:
#         decompress=args[0]
#         if decompress not in ["zip","tar","gz","tgz","tar.gz"]:
#             raise DownloaderError("Unknown decompression type")
#         if decompress in ["gz"]: # compression without filenames
#             targetname+="."+decompress
#     try:
#         fname,headers=urllib.request.urlretrieve(url,filename=targetname,reporthook=reporthook)
#     except urllib.error.URLError as ex:
#         print("Error downloading "+str(targetname)+": "+ex.reason)
#         raise DownloaderError("Can't download file")
#     if decompress == "zip":
#         ret=sp.call(["unzip",targetname,"-d",path],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")
#     elif decompress == "tar" or decompress == "tar.gz":
#         ret=sp.call(["tar","-xf",targetname,"-C",path],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")
#     elif decompress == "tgz":
#         ret=sp.call(["tar","-xfz",targetname,"-C",path],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")
#     elif decompress == "gz":
#         ret=sp.call(["gunzip",targetname],stdout=sys.stderr)
#         if ret!=0:
#             raise DownloaderError("Error extracting download")


# Path: utils/steamcmd.py
from utils.settings import settings 
from downloadermodules.url import download as url_download
import pwd
import os
import os.path
import subprocess as sp



# if a user has already installed steam to e.g ubuntu, steamcmd prefers to be installed in the same directory (or at least when steamcmd starts, it sends the error related things there as if it wants to be installed there.
STEAMCMD_DIR = os.path.expanduser(settings.user.downloader.getsection('steamcmd').get('steamcmd_path') or "~/.local/share/Steam/" if os.path.isdir(os.path.expanduser("~/.local/share/Steam/")) else "~/Steam/")
STEAMCMD_EXE = STEAMCMD_DIR + "steamcmd.sh"
STEAMCMD_URL = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz"

STEAMCMD_SCRIPTS = os.path.expanduser(settings.user.getsection('steamcmd').get('steamcmd_scripts',os.path.join(settings.user.getsection('core').get("alphagsm_path","~/.alphagsm"),"steamcmd_scripts" )))