Skip to content

Commit

Permalink
Merge pull request #11 from 130s/bug/10_install_webserver
Browse files Browse the repository at this point in the history
Separate webserver.py into module and script files (quick fix to #10).
  • Loading branch information
jihoonl committed Dec 25, 2014
2 parents aac51cc + fbf2e7a commit a5f3a6b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ project(roswww)
find_package(catkin REQUIRED)
catkin_package()
catkin_python_setup()

install(DIRECTORY script DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} USE_SOURCE_PERMISSIONS)
30 changes: 3 additions & 27 deletions src/roswww/webserver.py → script/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@

import socket
import subprocess
import tornado.ioloop # rosbridge installs tornado
import tornado.web

import roslib
roslib.load_manifest('roswww')
import rospy

import tornado.ioloop # rosbridge installs tornado
import tornado.web
from roswww.webrequest_handler import WebRequestHandler


def run_shellcommand(*args):
Expand All @@ -51,12 +50,10 @@ def run_shellcommand(*args):
return subprocess.Popen(args,
stdout=subprocess.PIPE).communicate()[0].strip()


def split_words(text):
'''return a list of lines where each line is a list of words'''
return [line.strip().split() for line in text.split('\n')]


def get_packages():
'''
Find the names and locations of all ROS packages
Expand All @@ -68,24 +65,6 @@ def get_packages():
packages = [{'name': name, 'path': path} for name, path in lines]
return packages


class WebRequestHandler(tornado.web.RequestHandler):

def initialize(self, packages):
'''
@type packages: {str, str}
@param packages: name and path of ROS packages.
'''
self.packages = packages

def get(self):
self.write(
"<h1>ROS web server successfully started.</h1><h3>Package List</h3>")
for package in self.packages:
self.write(
"<div style='font-size: 10px'>" + package['name'] + "</div>")


def create_webserver(packages):
'''
@type packages: {str, str}
Expand All @@ -109,7 +88,6 @@ def create_webserver(packages):

return application


def bind_webserver(application):
""" See if there's a default port, use 80 if not """
default_port, start_port, end_port = get_webserver_params()
Expand All @@ -123,7 +101,6 @@ def bind_webserver(application):

return bound


def get_webserver_params():
try:
default_port = rospy.get_param("http/default", 80)
Expand All @@ -139,7 +116,6 @@ def get_webserver_params():
else:
raise


def start_webserver(application):
try:
tornado.ioloop.IOLoop.instance().start()
Expand Down
54 changes: 54 additions & 0 deletions src/roswww/webrequest_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python

# Software License Agreement (BSD License)
#
# Copyright (c) 2013, Tokyo Opensource Robotics Kyokai Association
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Author: Jonathan Mace, Jihoon Lee, Isaac Isao Saito

import tornado.web


class WebRequestHandler(tornado.web.RequestHandler):

def initialize(self, packages):
'''
@type packages: {str, str}
@param packages: name and path of ROS packages.
'''
self.packages = packages

def get(self):
self.write(
"<h1>ROS web server successfully started.</h1><h3>Package List</h3>")
for package in self.packages:
self.write(
"<div style='font-size: 10px'>" + package['name'] + "</div>")

0 comments on commit a5f3a6b

Please sign in to comment.