Skip to content

Commit

Permalink
Fix Make compile_all and create_config
Browse files Browse the repository at this point in the history
  • Loading branch information
webdel-dd committed Jan 17, 2023
1 parent 9ef9e56 commit 2c4e822
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
2 changes: 1 addition & 1 deletion make/compile_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _dependency(self,snm,sver,ars):
utils.info("download headers and library ...")
nurl = utils.get_node_url()

if snm is not "lib_gcc" and snm is not "lib_stdcpp":
if snm!="lib_gcc" and snm!="lib_stdcpp":
appnm="headers_" + snm + ".zip"
utils.download_file(nurl + "getAgentFile.dw?name=" + appnm , spth + os.sep + appnm)
utils.unzip_file(spth + os.sep + appnm, spth + os.sep)
Expand Down
56 changes: 49 additions & 7 deletions make/create_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import sys
import importlib
import urllib
import utils
import json
import codecs

Expand All @@ -21,23 +20,66 @@
PROXY_USER=""
PROXY_PASSWORD=""


def is_py2():
return sys.version_info[0]==2

if is_py2():
def _py2_str_new(o):
if isinstance(o, unicode):
return o
elif isinstance(o, str):
return o.decode("utf8", errors="replace")
else:
return str(o).decode("utf8", errors="replace")
str_new=_py2_str_new
url_parse_quote_plus=urllib.quote_plus
else:
import urllib.parse
str_new=str
url_parse_quote_plus=urllib.parse.quote_plus
str_to_bytes=lambda s, enc="ascii": s.encode(enc, errors="replace")

def exception_to_string(e):
bamsg=False;
try:
if len(e.message)>0:
bamsg=True;
except:
None
try:
appmsg=None
if bamsg:
appmsg=str_new(e.message)
else:
appmsg=str_new(e)
return appmsg
except:
return u"Unexpected error."


if __name__ == "__main__":
print("This script generate core/config.json")
print("")
pthconfig=".." + os.sep + "core" + os.sep + "config.json"
if os.path.exists(pthconfig):
print("Error: File core/config.json already exists. Please remove before.")
else:
sys.path.append(".." + os.sep + "core")
sys.path.insert(0,".." + os.sep + "core")
objlibcom = importlib.import_module("communication")
set_cacerts_path = getattr(objlibcom, 'set_cacerts_path', None)
get_url_prop = getattr(objlibcom, 'get_url_prop', None)
ProxyInfo = getattr(objlibcom, 'ProxyInfo', None)
ProxyInfo = getattr(objlibcom, 'ProxyInfo', None)
objlibagt = importlib.import_module("agent")
obfuscate_password = getattr(objlibagt, 'obfuscate_password', None)
print("Create a new agent from your www.dwservice.net account to getting installation code.")
code = raw_input("Enter the code: ")
url = URL + "checkInstallCode.dw?code=" + urllib.quote_plus(code) # + "&osTypeCode=" + str(get_os_type_code()) +"&supportedApplications=" + urllib.quote_plus(spapp)
appcodemsg=u"Enter the code: "
if is_py2():
code = raw_input(appcodemsg)
else:
code = input(appcodemsg)

url = URL + "checkInstallCode.dw?code=" + url_parse_quote_plus(code) # + "&osTypeCode=" + str(get_os_type_code()) +"&supportedApplications=" + urllib.quote_plus(spapp)
try:
set_cacerts_path(".." + os.sep + "core" + os.sep + "cacerts.pem")
prx=ProxyInfo()
Expand Down Expand Up @@ -70,11 +112,11 @@
config['proxy_password']=PROXY_PASSWORD
s = json.dumps(config, sort_keys=True, indent=1)
f = codecs.open(pthconfig, 'wb')
f.write(s)
f.write(str_to_bytes(s))
f.close()
print("file core/config.json generated.")
except Exception as e:
print("Connection error: " + utils.exception_to_string(e))
print("Connection error: " + exception_to_string(e))

print("")
print("END.")
Expand Down
22 changes: 11 additions & 11 deletions make/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _py2_str_new(o):
import urllib.request
url_open=urllib.request.urlopen
bytes_to_str=lambda b, enc="ascii": b.decode(enc, errors="replace")
str_to_bytes=lambda s, enc="ascii": s.encode(enc, errors="replace")

def info(msg):
print(msg)
Expand Down Expand Up @@ -340,16 +341,15 @@ def get_node_url():
contents = url_open(MAIN_URL + "getAgentFile.dw?name=files.xml").read();
prp = xml_to_prop(contents)
return prp["nodeUrl"]




def read_json_file(fn):
appjs=None
if os.path.exists(fn):
f=None
try:
f = codecs.open(fn, 'rb', None, 'strict', 1)
appjs = json.loads(f.read())
f = codecs.open(fn, 'rb')
appjs = json.loads(bytes_to_str(f.read(),"utf8"))
except:
None
finally:
Expand All @@ -359,17 +359,17 @@ def read_json_file(fn):
return appjs

def write_json_file(conf,fn):
s = json.dumps(conf,fn, sort_keys=True, indent=1)
f = codecs.open(fn, 'wb', None, 'strict', 1)
f.write(s)
s = json.dumps(conf, sort_keys=True, indent=1)
f = codecs.open(fn, 'wb')
f.write(str_to_bytes(s,"utf8"))
f.close()

# UTILIZZATI DA DETECTINFO
#USED BY DETECTINFO
def path_exists(pth):
return os.path.exists(pth)

def file_open(filename, mode='rb', encoding=None, errors='strict', buffering=1):
return codecs.open(filename, mode, encoding, errors, buffering)
# UTILIZZATI DA DETECTINFO
def file_open(filename, mode='rb', encoding=None, errors='strict'):
return codecs.open(filename, mode, encoding, errors)
#USED BY DETECTINFO


0 comments on commit 2c4e822

Please sign in to comment.