Skip to content

Commit 6711e4f

Browse files
committed
0.34
1 parent 8b415b7 commit 6711e4f

File tree

1 file changed

+101
-25
lines changed

1 file changed

+101
-25
lines changed

binpythonfull.py

Lines changed: 101 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
####################################
1111
#build configure
1212

13-
ver="0.32-build-full"
13+
ver = "0.34-build-full"
1414

15-
libs_warning="1"
15+
libs_warning = "1"
1616
#1 is ture 0 is false.
1717
#Changing the value to 0 will close the prompt that the library does not exist
1818

1919
buildversion = "plus" #plus version and standard version
2020

21-
releases_ver="offical" + buildversion + "-building"
22-
23-
importlibs="os" #Don't use "import xxx"
21+
releases_ver = "offical" + buildversion + "-building"
22+
importlibs = "os" #Don't use "import xxx"
23+
cloudrunver = "1.01"
2424
#Imported library name, please use "importlibs="<library name>" instead of "import <library name>"
2525
#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
2626
#xxxxxxxxxxxxxx
@@ -78,6 +78,41 @@ def optreadfile():
7878
exec(getfilecode.read())
7979
input("Run finished. Enter to Shell.")
8080
sys.exit(0)
81+
class cloudrun:
82+
def get(pkgname):
83+
try:
84+
cloudrunenv = True
85+
getcoderes = urllib.request.urlopen(f"https://raw.githubusercontent.com/xingyujie/cloudrun-repository/main/{pkgname}.py")
86+
except(Exception, BaseException) as error:
87+
print("There is no network connection or the repository does not exist for this script")
88+
print("Error details are in cloudrun_error.log in the run directory")
89+
f = open("cloudrun_error.log", "a")
90+
f.write(str(error))
91+
try:
92+
exec(str(getcoderes.read().decode('utf-8')))
93+
getcoderes.close()
94+
except(Exception, BaseException) as error:
95+
print("run failed")
96+
print("Error details are in cloudrun_error.log in the run directory")
97+
f = open("cloudrun_error.log", "a")
98+
f.write(str(error))
99+
def load(url):
100+
try:
101+
cloudrunenv = True
102+
getcoderes = urllib.request.urlopen(url)
103+
except(Exception, BaseException) as error:
104+
print("There is no network connection or the repository does not exist for this script")
105+
print("Error details are in cloudrun_error.log in the run directory")
106+
f = open("cloudrun_error.log", "a")
107+
f.write(str(error))
108+
try:
109+
exec(getcoderes.read().decode('utf-8'))
110+
getcoderes.close()
111+
except(Exception, BaseException) as error:
112+
print("run failed")
113+
print("Error details are in cloudrun_error.log in the run directory")
114+
f = open("cloudrun_error.log", "a")
115+
f.write(str(error))
81116
try:
82117
#base import
83118
import getopt
@@ -86,6 +121,9 @@ def optreadfile():
86121
import os
87122
import timeit
88123
import pdb
124+
import random
125+
import webbrowser
126+
import urllib.request
89127
#fix for exit()
90128
from sys import exit
91129
#import for http_server
@@ -204,8 +242,9 @@ def binpython_shell():
204242
"""
205243
#helpinfo plus
206244
helpinfoplus = """
207-
-p --plus Open BINPython IDE Plus Code Editor(beta) with http web server
245+
-p <port> --plus=<port> Open BINPython IDE Plus Code Editor(beta) with http web server
208246
-e --example Run various code examples through BINPython
247+
-c --cloudrun Run Python scripts in the cloud via CloudRun (into CloudRun CLI)
209248
"""
210249
#base + plus, print full help
211250
def outputfullhelp():
@@ -222,7 +261,7 @@ def outputfullhelp():
222261
#getopt
223262
try:
224263
#set options
225-
opts,args = getopt.getopt(sys.argv[1:],'-h-f:-s:-g-i-p-e-v',['help','file=','server=','gui','idle','plus','example','version'])
264+
opts,args = getopt.getopt(sys.argv[1:],'-h-f:-s:-g-i-p:-e-c-v',['help','file=','server=','gui','idle','plus','example','cloudrun','version'])
226265
#set getopt error prompt
227266
except getopt.GetoptError as err:
228267
print("Please check help:")
@@ -255,6 +294,7 @@ def outputfullhelp():
255294
if opt_name in ('-s','--server'):
256295
#-s set simple http server(support html or files transfer)
257296
server_port = opt_value
297+
webbrowser.open(f"http://127.0.0.1:{server_port}")
258298
exec("""
259299
PORT = """ + server_port + """
260300
@@ -306,6 +346,7 @@ def show():
306346
sys.exit()
307347
#-p binpython ideplus
308348
if opt_name in ('-p','--plus'):
349+
ideplusport = opt_value
309350
import pywebio.input
310351
from pywebio.input import *
311352
from pywebio.output import *
@@ -317,12 +358,12 @@ def show():
317358
import webbrowser
318359
print("______________________________________")
319360
print("BINPython WEB IDE STARTED")
320-
print("""
361+
print(f"""
321362
Welcome to BINPython IDEPlus!
322-
The service starts on port 22948 (http), the program will automatically open the browser, if not, please manually open http://localhost:22948 in the browser
363+
HTTP Port: {ideplusport}
323364
""")
324365
#open browser
325-
webbrowser.open("http://localhost:22940")
366+
webbrowser.open(f"http://127.0.0.1:{ideplusport}")
326367
#IDE Plus main
327368
def line():
328369
put_text('_______________________',
@@ -331,9 +372,9 @@ def line():
331372
#set bootstrap ui(bar)
332373
def head():
333374
set_env(title="BINPython IDE Plus", auto_scroll_bottom=True)
334-
put_html("""
375+
put_html(f"""
335376
<nav class="navbar navbar-expand-lg navbar-light bg-light">
336-
<a class="navbar-brand" href="http://localhost:22940"></a>
377+
<a class="navbar-brand" href="http://localhost:{ideplusport}"></a>
337378
<img src="https://github.com/xingyujie/binpython/blob/main/py.ico?raw=true" width="30" height="30" class="d-inline-block align-top" alt="">
338379
BINPython IDEPlus
339380
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
@@ -342,10 +383,10 @@ def head():
342383
<div class="collapse navbar-collapse" id="navbarSupportedContent">
343384
<ul class="navbar-nav mr-auto">
344385
<li class="nav-item">
345-
<a class="nav-link active" aria-current="page" href="http://localhost:22940/">Home</a>
386+
<a class="nav-link active" aria-current="page" href="http://localhost:{ideplusport}/">Home</a>
346387
</li>
347388
<li class="nav-item">
348-
<a class="nav-link" href="http://localhost:22940/?app=ideplus">IDEPlus</a>
389+
<a class="nav-link" href="http://localhost:{ideplusport}/?app=ideplus">IDEPlus</a>
349390
</li>
350391
</a>
351392
</ul>
@@ -355,9 +396,9 @@ def head():
355396
""")
356397
def plushead():
357398
set_env(title="BINPython IDE Plus", auto_scroll_bottom=True)
358-
put_html("""
399+
put_html(f"""
359400
<nav class="navbar navbar-expand-lg navbar-light bg-light">
360-
<a class="navbar-brand" href="http://localhost:22940"></a>
401+
<a class="navbar-brand" href="http://localhost:{ideplusport}"></a>
361402
<img src="https://github.com/xingyujie/binpython/blob/main/py.ico?raw=true" width="30" height="30" class="d-inline-block align-top" alt="">
362403
BINPython IDEPlus
363404
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
@@ -366,10 +407,10 @@ def plushead():
366407
<div class="collapse navbar-collapse" id="navbarSupportedContent">
367408
<ul class="navbar-nav mr-auto">
368409
<li class="nav-item">
369-
<a class="nav-link" href="http://localhost:22940/">Home</a>
410+
<a class="nav-link" href="http://localhost:{ideplusport}/">Home</a>
370411
</li>
371412
<li class="nav-item">
372-
<a class="nav-link active" aria-current="page" href="http://localhost:22940/?app=ideplus">IDEPlus</a>
413+
<a class="nav-link active" aria-current="page" href="http://localhost:{ideplusport}/?app=ideplus">IDEPlus</a>
373414
</li>
374415
</a>
375416
</ul>
@@ -389,14 +430,14 @@ def aboutideplus():
389430
390431
""")
391432
def welcomecard():
392-
put_html("""
433+
put_html(f"""
393434
<div class="jumbotron">
394435
<h1 class="display-3">Welcome to BINPython!</h1>
395436
<p class="lead">This is a portable IDE environment for BINPython</p>
396437
<hr class="my-4">
397438
<p>Fast and portable, runs via BINPython</p>
398439
<p class="lead">
399-
<a class="btn btn-primary btn-lg" href="http://localhost:22940/?app=ideplus" role="button">Try IDE Plus!</a>
440+
<a class="btn btn-primary btn-lg" href="http://localhost:{ideplusport}/?app=ideplus" role="button">Try IDE Plus!</a>
400441
</p>
401442
</div>
402443
""")
@@ -405,11 +446,11 @@ def index():
405446
head()
406447
welcomecard()
407448
put_markdown("## Features")
408-
put_link("IDEPlus", url='http://localhost:22940/?app=ideplus')
449+
put_link("IDEPlus", url=f'http://localhost:{ideplusport}/?app=ideplus')
409450
line()
410-
put_link("About BINPython", url='http://localhost:22940/?app=aboutideplus')
451+
put_link("About BINPython", url=f'http://localhost:{ideplusport}/?app=aboutideplus')
411452
line()
412-
put_link("View Code", url='http://localhost:22940/?app=viewcode')
453+
put_link("View Code", url=f'http://localhost:{ideplusport}/?app=viewcode')
413454
def idehead():
414455
set_env(title="BINPython IDE Plus", auto_scroll_bottom=True)
415456
put_html("<h1>BINPython IDE Plus</h1>")
@@ -443,8 +484,9 @@ def viewcode():
443484
f = open(viewcode_code,encoding = "utf-8")
444485
put_code(f.read(), language='python')
445486
if __name__ == '__main__':
446-
start_server([index, ideplus, aboutideplus, viewcode], debug=True, port= 22940)
487+
start_server([index, ideplus, aboutideplus, viewcode], debug=True, port=ideplusport)
447488
pywebio.session.hold()
489+
config(title="BINPython") #pywebio global title
448490
#binpython examples
449491
if opt_name in ('-e','--example'):
450492
print("Welcome to BINPython example")
@@ -552,6 +594,39 @@ def examplerequests():
552594
#main shell
553595
binpython_shell()
554596
sys.exit()
597+
598+
if opt_name in ('-c','--cloudrun'):
599+
600+
print("Welcome to CloudRun CLI. Let your script run in the cloud with BINPython")
601+
print('Type "help" for help information')
602+
while True:
603+
cloudruncli = input("cloudrun~ ")
604+
if cloudruncli == 'help':
605+
print("""
606+
CloudRun Help:
607+
get -- Enter application/script name to get run from software repository
608+
load -- Run scripts from custom URL
609+
version -- CloudRun Version
610+
help -- run this help
611+
""")
612+
if cloudruncli == 'get':
613+
print("Get apps/scripts in software repository")
614+
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")
615+
print()
616+
pkgname = input("packagename: ")
617+
cloudrun.get(pkgname)
618+
if cloudruncli == 'load':
619+
print("Let CloudRun run scripts through a custom server")
620+
print("The format should be like this: http://domain.com/filename.py")
621+
url = input("Python script URL: ")
622+
cloudrun.load(url)
623+
if cloudruncli == 'version':
624+
print(f"CloudRun-{cloudrunver} BINPython version By:Edward Hsing(xingyujie) AGPL-3.0 LICENSE")
625+
if cloudruncli == '':
626+
pass
627+
else:
628+
pass
629+
555630
#go main shell
556631
#custom welcome script
557632
try:
@@ -609,6 +684,7 @@ def showinfo():
609684
def loadmain(key):
610685
global plugin_loadmain
611686
plugin_loadmain = key
687+
612688
#binpython_plugin_loadmain("function.py")
613689
try:
614690
f = open("binpython_plugin/pluginconfig.binpython",encoding = "utf-8")
@@ -623,6 +699,6 @@ def loadmain(key):
623699
startupcode = open(filename.read(),encoding = "utf-8")
624700
exec(startupcode.read())
625701
except:
626-
binpython_shell()
702+
pass
627703
#go shell
628704
binpython_shell()

0 commit comments

Comments
 (0)