Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
This would close issue #4
  • Loading branch information
lambdalisue committed Oct 21, 2014
2 parents 2b35c07 + 113f42c commit 098373a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
6 changes: 4 additions & 2 deletions scripts/shareboard
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def start(args):
def set(args):
url = 'http://%s:%s/' % (args.host, args.port)
kwargs = {
'data': {'text': args.text},
'data': {'text': args.text, 'filename': args.filename},
'timeout': args.timeout,
}
requests.post(url, **kwargs)
Expand Down Expand Up @@ -93,8 +93,10 @@ def main():
# create the subparser for the 'set' command
parser_set = subparsers.add_parser('set',
help='Post new data to the shareboard')
parser_set.add_argument('text', type=unicode,
parser_set.add_argument('text',
help='Text data to be seted to the shareboard')
parser_set.add_argument('-f', '--filename', default='index.html',
help='Filename of the text data. To use resolve relative path')
parser_set.add_argument('-t', '--timeout', default=DEFAULT_TIMEOUT, type=float,
help='Seconds to timeout the connection')
parser_set.set_defaults(func=set)
Expand Down
6 changes: 3 additions & 3 deletions src/shareboard/gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, cui_server):
def run(self):
self.cui_server.start()

def emit_request_recieved(self, value):
self.request_recieved.emit(value)
def emit_request_recieved(self, value, filename='index.html'):
self.request_recieved.emit(value, filename)

# --- signal
request_recieved = QtCore.Signal(unicode)
request_recieved = QtCore.Signal(unicode, unicode)
6 changes: 3 additions & 3 deletions src/shareboard/gui/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ def print_(self):
self.view.print_(printer)

# --- slots
@QtCore.Slot(unicode)
def update(self, value):
@QtCore.Slot(unicode, unicode)
def update(self, value, filename='index.html'):
# save vertical/horizontal scrollbar value
m = self.view.page().mainFrame()
v = m.scrollBarValue(QtCore.Qt.Vertical)
h = m.scrollBarValue(QtCore.Qt.Horizontal)
# set new HTML (value should be unicode)
self.view.setHtml(value)
self.view.setHtml(value, QtCore.QUrl.fromLocalFile(filename))
# update vertical/horizontal scrollbar value
m = self.view.page().mainFrame()
m.setScrollBarValue(QtCore.Qt.Vertical, v)
Expand Down
8 changes: 5 additions & 3 deletions src/shareboard/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class ShellParser(object):
def __init__(self, command):
self.command = command

def parse(self, text, encoding='utf-8'):
p = subprocess.Popen(self.command, shell=True,
def parse(self, text, cwd=None, encoding='utf-8'):
if cwd == "":
cwd = None
p = subprocess.Popen(self.command, shell=True, cwd=cwd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
# the text should be encoded to use in Shell
stdout, stderr = p.communicate(data.encode(encoding))
stdout, stderr = p.communicate(text.encode(encoding))
# the text should be decoded to use in Python
return unicode(stdout, encoding)
19 changes: 11 additions & 8 deletions src/shareboard/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# vim: set fileencoding=utf-8 :
import cgi
import urlparse
import os.path
from BaseHTTPServer import HTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler

Expand All @@ -17,7 +18,7 @@ def do_GET(self):
# respond data
self.send_response(200)
self.end_headers()
self.wfile.write(self.text)
self.wfile.write(getattr(self.server, 'text', ''))

def do_POST(self):
try:
Expand All @@ -34,18 +35,20 @@ def do_POST(self):
return
# decode text to unicode
text = unicode(request['text'].value, self.server.encoding)
filename = request.getvalue('filename', 'index.html')
# respond OK
self.send_response(200)
self.end_headers()
self.wfile.write('OK')
# modify the text with callback if it's specified
if self.server.callback:
text = self.callback(text)
cwd = os.path.dirname(filename)
text = self.server.callback(text, cwd)
# store the value
self.text = text
self.server.text = text
# emit request recieved if it's required
if hasattr(self.server, 'emitter'):
self.server.emitter.emit_request_recieved(text)
# respond OK
self.send_response(200)
self.end_headers()
self.wfile.write('OK')
self.server.emitter.emit_request_recieved(text, filename)
except Exception, e:
print "Error:", e
self.send_response(500, e)
Expand Down

0 comments on commit 098373a

Please sign in to comment.