#Changing the value to 0 will close the prompt that the library does not exist
releases_ver="offical"
importlibs="os"
cloudrunver="1.04"
cmdver="0.08"
#Imported library name, please use "importlibs="<library name>" instead of "import <library name>"
#Please note: The "importlibs" function does not support loading functions (such as from xxxx import xxxx, if necessary, please write it in the following location. However, please note that this operation may have the risk of error reporting, please report issues or solve it yourself
#xxxxxxxxxxxxxx
#from xxxx import xxxx
#xxxxxxxxxxxxxx
####################################
#BINPython function and variable START
classbinpythoninfo:
defver():
print(ver)
deflibs_warning():
print(libs_warning)
defreleases_ver():
print(releases_ver)
defbuild_importlibs():
print(importlibs)
fromosimportmakedirs
importtime
#get system info(windows or linux ...)
importplatform
sys=platform.system()
#if system is windows, then enable setwindowtitle() function
print("ver: "+ver+" buildversion: "+" libs_warning settings:"+libs_warning+" releases full version: "+releases_ver+" custom library that has been build: "+importlibs)
print("Warning: Some GUI (graphical) libraries for BINPython do not exist, such as tkinter and turtle. Because they are not built when they are built. If you need to fix this warning, please complete the support libraries imported in the source code at build time (use pip or build it yourself), if your system does not support these libraries, you can remove or change this hint in the source code and rebuild")
print("")
#import math
try:
importfractions
importcmath
exceptImportError:
iflibs_warning=="1":
print("Warning: Some math or computation libraries for BINPython do not exist, such as fractions and cmath. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild")
print("")
#import for normal
try:
#str
importrlcompleter
importarray
importxlrd
exceptImportError:
iflibs_warning=="1":
print("Warning: Some libraries for functions, data types, etc. for BINPython do not exist, such as rlcomplter and array. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild")
print("")
try:
importfilecmp
importtempfile
exceptImportError:
iflibs_warning=="1":
print("Warning: Some file manipulation libraries for BINPython do not exist, such as filecmp and tempfile. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild")
print("")
#main BINPython
defbinpython_welcome_text():
print("BINPython "+ver+"-"+releases_ver+" (Python Version:"+platform.python_version() +") By: Edward Hsing(Xing Yu Jie) https://github.com/xingyujie/binpython[Running on "+platform.platform() +" "+platform.version() +"]")
print('Type "about", "help", "copyright", "credits" or "license" for more information. Type "binpython_cmd" to enter BINPython CMD')
defbinpython_shell():
whileTrue:
try:
pycmd=input(">>> ")
ifpycmdinglobals().keys():
print(globals()[pycmd])
continue
elifpycmd=='about':
print("BINPython By: Edward Hsing(Xing Yu Jie)[https://github.com/xingyujie] AGPL-3.0 LICENSE Release")
elifpycmd=='help':
print("Type help() for interactive help, or help(object) for help about object.")
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more information.
""")
elifpycmd=='license':
print("Type license() to see the full license text")
elifpycmd=='binpython_cmd':
binpython_cmd()
else:
exec(pycmd)
exceptKeyboardInterrupt:
print("KeyboardInterrupt")
sys.exit()
exceptExceptionaserr:
print(err)
try:
optreadfile()
except:
pass
defcloudruncli():
print("Welcome to CloudRun CLI. Let your script run in the cloud with BINPython")
print('Type "help" for more information')
whileTrue:
cloudruncli=input("cloudrun~ ")
ifcloudruncli=='help':
print("""
CloudRun Help:
get -- Enter application/script name to get run from software repository
load -- Run scripts from custom URL
editsource -- Set up custom sources and save via configuration files
shell -- Go to BINPython Shell
version -- CloudRun Version
help -- show this help
exit -- quit cloudrun
""")
ifcloudruncli=='get':
print("Get apps/scripts in software repository")
print("Under normal circumstances, we review the code of the software repositories and generally do not have any malware. But we will not take any legal responsibility")
print()
pkgname=input("packagename: ")
ifpkgname=='':
pass
else:
cloudrun.get(pkgname)
ifcloudruncli=='load':
print("Let CloudRun run scripts through a custom server")
print("The format should be like this: http://domain.com/filename.py")
url=input("Python script URL: ")
ifurl=='':
pass
else:
cloudrun.load(url)
ifcloudruncli=='editsource':
print('caution! The set software source must be in a standard format, otherwise it may not work, like http://127.0.0.1/, if you set http://127.0.0.1, it will not work properly, even if there is one less "/"!')
entersource=input("Please input sources server address: ")
cloudrun.editsource(entersource)
print("success!")
ifcloudruncli=='shell':
binpython_shell()
ifcloudruncli=='version':
print(f"CloudRun-{cloudrunver} BINPython version By:Edward Hsing(Xing Yu Jie) AGPL-3.0 LICENSE")
Welcome to BINPython CMD! Choose a method to install BINPython CMD:
1. WEB graphical interactive installation (recommended)
2. Interactive text interface (also for non-graphical devices)
Please enter a number (1/2):
""")
ifwhichmethod=='1':
getwebui=open(get_resource_path('webui.py'))
webui=getwebui.read()
exec(webui)
ifwhichmethod=='2':
print('''
The file system cannot be found or there is an incomplete file system.
type "getfs" to download a file system;
type "getfsurl" to download a filesystem via a custom url;
Type "getfsfile" to unzip the filesystem via file;
type "mkbpfs" to make a new file system;
type "exit" to exit;
type "shell" to force entry into the shell.
* After forcing into the shell, you can create bpfs via "mkbpfs" command or use "adduser", "setdefaultuser" and other commands to build the filesystem step by step. But we don't recommend it, it may be more problematic and more complex
print('Unable to switch to BINPython userprofile: Default user not found. To use a temporary directory user, use "adduser" and "setdefaultuser <username>" to create a user and set default user')
'Run a Python script file (*.py) Usage: python <filename>.py'
ifarg=='':
binpython_shell()
f=open(arg, "r")
exec(f.read())
defdo_seteditor(self, arg):
'Set a default Python or Text file code editor usage: seteditor <editorname>. like: "seteditor code" (Open code via Visual Studio Code when using the "edit <filename>" command). "seteditor notepad" (Open the code through Notepad that comes with Windows)'
'Before using this command, you must use "seteditor <editorname>" to set the editor (see the usage of this parameter for details), otherwise it cannot be called up. edit usage: edit <filename>'
'To change the software source, usage: editsouce <souceurl>. Please pay attention to the software source specification, otherwise you will get an error. <souceurl> like this: http://xxx.com/'
'Create a temporary user, logging out will destroy the user space'
print("You are trying to create a temporary user, this user space is only used for demonstration, testing and learning. When this user is logged out, all user data will also be deleted")
print("..........")
time.sleep(0.3)
print('Please note: the username of the temporary user is "tempuser" and the "tempuser" user is being created')
'Initialize the custom CMD command file. After opening, you can use the "def do_cloudrunget(self, arg):" code to write your own commands through the "/binpython_files/cmd/cmd.py" file.'
f.write('#Initialize the custom CMD command file, you can write your own command through the "def do_cloudrunget(self, arg):" code, please refer to "https://docs.python.org/3/library/cmd.html" for details')
except(Exception, BaseException) aserror:
print('Can not initcmd, please see the log "binpython_cmd_error.log" for details')