Skip to content

Commit

Permalink
BigBashView 3.0 + BigControlCenter
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbruno committed Jun 5, 2019
1 parent 2bb61e3 commit 575327a
Show file tree
Hide file tree
Showing 37 changed files with 482 additions and 347 deletions.
2 changes: 1 addition & 1 deletion bigbashview/usr/share/bigbashview/bbv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__all__ = ("main", "ui", "globals", "parser")
__all__ = ("main", "ui", "globals", "parser")
31 changes: 20 additions & 11 deletions bigbashview/usr/share/bigbashview/bbv/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,32 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os,sys
import os
import sys

APP_NAME = "Big Bash View"
APP_VERSION = "2.1"
PROGDIR=os.path.dirname(os.path.abspath(sys.argv[0]))
PROGDIR = os.path.dirname(os.path.abspath(sys.argv[0]))

if os.path.isdir(os.sep.join((PROGDIR,".hg"))):
if os.path.isdir(os.sep.join((PROGDIR, ".hg"))):
try:
import subprocess
po = subprocess.Popen("hg heads --template '{rev}'", stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
po = subprocess.Popen(
"hg heads --template '{rev}'", stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = po.communicate()
APP_VERSION+=' (DEV. VERSION) rev %s' %stdout
except:
APP_VERSION += ' (DEV. VERSION) rev %s' % stdout
except Exception:
pass

DATA_DIR = os.path.expanduser("~/.bigbashview") # TODO: Check portability issues
ICON = os.sep.join((PROGDIR,"bbv","img","icone.png"))
ADDRESS = lambda: '127.0.0.1'
PORT = lambda: 9000
COMPAT=False
# TODO: Check portability issues
DATA_DIR = os.path.expanduser("~/.bigbashview")
ICON = os.sep.join((PROGDIR, "bbv", "img", "icone.png"))


def ADDRESS(): return '127.0.0.1'


def PORT(): return 9000


COMPAT = False
64 changes: 32 additions & 32 deletions bigbashview/usr/share/bigbashview/bbv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,38 @@
import sys
import os
import getopt
import re

from bbv import globals as globaldata
from bbv.server.bbv2server import run_server


class Main:
width = -1
height = -1
toolkit = "qt5"
url = "/"
window_state="normal"
window_state = "normal"
icon = globaldata.ICON

def __init__(self):
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'hs:vt:w:i:c', ['help', 'screen=',
'version', "toolkit=", 'window_state=', 'icon=', 'compatibility-mode' ])
'version', "toolkit=", 'window_state=', 'icon=', 'compatibility-mode'])

except getopt.error, msg:
print msg
print 'for help use --help'
except getopt.error as msg:
print(msg)
print('for help use --help')
sys.exit(2)

if len(args):
self.url=args[0]
self.url = args[0]

for o, a in opts:
if o in ('-h', '--help'):
self.help()

elif o in ('-v','--version'):
print globaldata.APP_NAME, globaldata.APP_VERSION
elif o in ('-v', '--version'):
print(globaldata.APP_NAME, globaldata.APP_VERSION)
sys.exit()

elif o in ('-s', '--screen'):
Expand All @@ -67,29 +67,29 @@ def __init__(self):

self.width, self.height = args

#Window Size
# Window Size
self.width = int(self.width)
self.height = int(self.height)

elif o in ('-t','--toolkit'):
elif o in ('-t', '--toolkit'):
if a in ("gtk2", "qt5"):
self.toolkit = a
else:
self.toolkit = "auto"
elif o in ('-w','--window_state'):
if a in ("normal","maximized","fullscreen"):
self.window_state=a
elif o in ('-i','--icon'):
elif o in ('-w', '--window_state'):
if a in ("normal", "maximized", "fullscreen"):
self.window_state = a
elif o in ('-i', '--icon'):
if os.path.exists(a):
globaldata.ICON = a
elif o in ('-c','--compatibility-mode'):
globaldata.COMPAT = True
elif o in ('-c', '--compatibility-mode'):
globaldata.COMPAT = True

#Create data folder if doesn't exists...
# Create data folder if doesn't exists...
if not os.path.isdir(globaldata.DATA_DIR):
os.mkdir(globaldata.DATA_DIR)

#construct window
# construct window
if self.toolkit == "auto":
try:
from bbv.ui import qt5
Expand All @@ -104,9 +104,9 @@ def __init__(self):
has_gtk2 = False

if not(has_qt5) and not(has_gtk2):
print >> sys.stderr, ('bbv needs PyGTK or PyQt '
'to run. Please install '
'the latest stable version')
print(('bbv needs PyGTK or PyQt '
'to run. Please install '
'the latest stable version'), file=sys.stderr)
sys.exit(1)

elif has_qt5:
Expand All @@ -123,9 +123,9 @@ def __init__(self):

if not has_qt5:
from bbv.ui import qt5
print >> sys.stderr, ('bbv needs PyQt '
'to run. Please install '
'the latest stable version')
print(('bbv needs PyQt '
'to run. Please install '
'the latest stable version'), file=sys.stderr)

sys.exit(1)

Expand All @@ -139,28 +139,28 @@ def __init__(self):
has_gtk2 = False

if not has_gtk2:
print >> sys.stderr, ('bbv needs PyGTK '
'to run. Please install '
'the latest stable version')
print(('bbv needs PyGTK '
'to run. Please install '
'the latest stable version'), file=sys.stderr)

sys.exit(1)

self.window = gtk2.Window()


def help(self):
print sys.argv[0], '[-h|--help] [-s|--screen=widthxheight] [-v|--version] [-t|--toolkit=[gtk2|qt5|]] [-w|--window_state=[normal|maximized|fullscreen]] [-i|--icon image] [-c|--compatibility-mode] URL'
print(sys.argv[0], '[-h|--help] [-s|--screen=widthxheight] [-v|--version] [-t|--toolkit=[gtk2|qt5|]] [-w|--window_state=[normal|maximized|fullscreen]] [-i|--icon image] [-c|--compatibility-mode] URL')
sys.exit()

def run(self, start_server=True):
server = run_server() if start_server else None

self.window.set_size(self.width,self.height)
self.window.set_size(self.width, self.height)
self.window.show(self.window_state)
if self.url.find('://') == -1:
if not self.url.startswith('/'):
self.url = '/'+self.url
self.url = "http://%s:%s%s" %(globaldata.ADDRESS(),globaldata.PORT(),self.url)
self.url = "http://%s:%s%s" % (globaldata.ADDRESS(),
globaldata.PORT(), self.url)
self.window.load_url(self.url)
globaldata.ICON = self.icon
self.window.run()
Expand Down
4 changes: 2 additions & 2 deletions bigbashview/usr/share/bigbashview/bbv/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008 Wilson Pinto Júnior <wilson@openlanhouse.org>
# Copyright (C) 2008 Wilson Pinto J�nior <wilson@openlanhouse.org>
# Copyright (C) 2011 Thomaz de Oliveira dos Reis <thor27@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -17,4 +17,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__all__ = ("views", "bbv2server")
__all__ = ("views", "bbv2server")
37 changes: 20 additions & 17 deletions bigbashview/usr/share/bigbashview/bbv/server/bbv2server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import sys
import socket
import threading
import inspect
import time
import views
from . import views
import os
try:
from bbv import globals as globaldata
except ImportError:
import globaldata
from . import globaldata


class Server(threading.Thread):
def _get_subclasses(self, classes=None):
Expand Down Expand Up @@ -59,29 +60,31 @@ def run(self):
""" Run the webserver """
ip = globaldata.ADDRESS()
port = globaldata.PORT()
sys.argv = [ sys.argv[0], '' ]
sys.argv[1] = ':'.join((ip,str(port)))
sys.argv = [sys.argv[0], '']
sys.argv[1] = ':'.join((ip, str(port)))

urls = self.get_urls()
classes = self.get_classes()
self.app = web.application(urls, classes)
self.app.run()

def stop(self):
print 'Waiting for server to shutdown...'
print('Waiting for server to shutdown...')
self.app.stop()
os.kill(os.getpid(), 15)


def run_server(ip='127.0.0.1',background=True):
def run_server(ip='127.0.0.1', background=True):
soc = socket.socket()
for port in range(19000,19100):
for port in range(19000, 19100):
try:
soc.bind((ip,port))
soc.bind((ip, port))
soc.close()
break
except socket.error, e:
if e[0] != 98:
except socket.error as e:
if e.errno != 98:
raise socket.error(e)
print 'Port %d already in use, trying next one' %port
print('Port %d already in use, trying next one' % port)

globaldata.ADDRESS = lambda: ip
globaldata.PORT = lambda: port
Expand All @@ -95,16 +98,16 @@ def run_server(ip='127.0.0.1',background=True):
server.daemon = True
web.config.debug = False
server.start()
#Wait for server to respond...
# Wait for server to respond...
while True:
try:
con = socket.create_connection((ip,port))
con = socket.create_connection((ip, port))
con.close()
break
except socket.error, e:
if e[0] != 111:
except socket.error as e:
if e.errno != 111:
raise socket.error(e)
print 'Waiting for server...'
print('Waiting for server...')
time.sleep(0.1)

return server
Expand Down
11 changes: 8 additions & 3 deletions bigbashview/usr/share/bigbashview/bbv/server/globaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

address = lambda: '127.0.0.1'
port = lambda: 9000
APP_VERSION = "2.0"

def address(): return '127.0.0.1'


def port(): return 9000


APP_VERSION = "2.0"
42 changes: 25 additions & 17 deletions bigbashview/usr/share/bigbashview/bbv/server/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shlex
from ..utils import get_env_for_shell
from ..utils import convert_str_bool
from ..utils import to_s

try:
from chameleon import PageTemplate
Expand All @@ -15,34 +16,40 @@
sys.stderr.write('Chameleon >= 2.5 not available. Parser will not work\n')
is_chameleon_available = False

def parse_output(text,mode):

def parse_output(text, mode):
output_parser = {
'int':int,
'float':float,
'bool':convert_str_bool,
'python':eval,
'array': lambda x:shlex.split(x," "),
'array_int': lambda x:[int(i) for i in shlex.split(x," ")],
'array_float': lambda x:[float(i) for i in shlex.split(x," ")],
'array_bool': lambda x:[convert_str_bool(i) for i in shlex.split(x," ")],
'str':lambda x:x
'int': int,
'float': float,
'bool': convert_str_bool,
'python': eval,
'array': lambda x: shlex.split(x, " "),
'array_int': lambda x: [int(i) for i in shlex.split(x, " ")],
'array_float': lambda x: [float(i) for i in shlex.split(x, " ")],
'array_bool': lambda x: [convert_str_bool(i) for i in shlex.split(x, " ")],
'str': lambda x: to_s(x)
}
try:
return output_parser[mode](text)
except (ValueError,KeyError):
except (ValueError, KeyError):
return text

def execute(command,context,context_ext):

def execute(command, context, context_ext):
env = os.environ.copy()
context.update(context_ext)
for key in context:
env[key] = str(context[key])
env.update(get_env_for_shell(context['request']))
po = subprocess.Popen(command.encode('utf-8'), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=env)
(stdout,stderr) = po.communicate()
po = subprocess.Popen(command.encode('utf-8'), stdin=None,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=env)
(stdout, stderr) = po.communicate()
stdout = to_s(stdout)
stderr = to_s(stderr)
sys.stderr.write(stderr)
mode = stderr.split('\n')[0].strip()
return parse_output(stdout,mode)
return parse_output(stdout, mode)


def sh_expression(command):
def compiler(target, engine):
Expand All @@ -55,10 +62,11 @@ def compiler(target, engine):
return [ast.Assign(targets=[target], value=value)]
return compiler


if is_chameleon_available:
PageTemplate.expression_types['sh'] = sh_expression

def parse(template,qs):
def parse(template, qs):
return PageTemplate(template)(request=qs)
else:
parse = lambda template,qs: template
def parse(template, qs): return template
Loading

0 comments on commit 575327a

Please sign in to comment.