Merge pull request #49 from brousch/serve_command

Added a 'serve' command to serve bin/ over SimpleHTTPServer
This commit is contained in:
Mathieu Virbel 2013-10-29 09:45:00 -07:00
commit a8dba50178
2 changed files with 25 additions and 7 deletions

View file

@ -16,7 +16,9 @@ import fcntl
import os
import re
import shelve
import SimpleHTTPServer
import socket
import SocketServer
import sys
import zipfile
from select import select
@ -47,6 +49,7 @@ USE_COLOR = 'NO_COLOR' not in environ
# error, info, debug
LOG_LEVELS_C = (RED, BLUE, BLACK)
LOG_LEVELS_T = 'EID'
SIMPLE_HTTP_SERVER_PORT = 8000
class ChromeDownloader(FancyURLopener):
@ -75,7 +78,8 @@ class BuildozerCommandException(BuildozerException):
class Buildozer(object):
standard_cmds = ('clean', 'update', 'debug', 'release', 'deploy', 'run')
standard_cmds = ('clean', 'update', 'debug', 'release',
'deploy', 'run', 'serve')
def __init__(self, filename='buildozer.spec', target=None):
super(Buildozer, self).__init__()
@ -734,12 +738,13 @@ class Buildozer(object):
print
print 'Target commands:'
print ' clean Clean the target environment'
print ' update Update the target dependencies'
print ' debug Build the application in debug mode'
print ' release Build the application in release mode'
print ' deploy Deploy the application on the device'
print ' run Run the application on the device'
print ' clean Clean the target environment'
print ' update Update the target dependencies'
print ' debug Build the application in debug mode'
print ' release Build the application in release mode'
print ' deploy Deploy the application on the device'
print ' run Run the application on the device'
print ' serve Serve the bin directory via SimpleHTTPServer'
for target, m in targets:
mt = m.get_target(self)
@ -838,6 +843,16 @@ class Buildozer(object):
'''
print 'Buildozer {0}'.format(__version__)
def cmd_serve(self, *args):
'''Serve the bin directory via SimpleHTTPServer
'''
os.chdir(self.bin_dir)
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", SIMPLE_HTTP_SERVER_PORT), handler)
print("Serving via HTTP at port {}".format(SIMPLE_HTTP_SERVER_PORT))
print("Press Ctrl+c to quit serving.")
httpd.serve_forever()
#
# Private
#

View file

@ -107,3 +107,6 @@ class Target(object):
def cmd_run(self, *args):
self.buildozer.prepare_for_build()
def cmd_serve(self, *args):
self.buildozer.cmd_serve()