Skip to content

Move twisted server and pydas out of slicer python environment #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ class Pyslicer_Notification extends ApiEnabled_Notification
{
public $moduleName = 'pyslicer';
public $_moduleComponents=array('Api');


/** Register callbacks */
public function init()
{
$this->enableWebAPI($this->moduleName);
$this->enableWebAPI($this->moduleName);
$fc = Zend_Controller_Front::getInstance();
$this->moduleWebroot = $fc->getBaseUrl().'/modules/'.$this->moduleName;
$this->coreWebroot = $fc->getBaseUrl().'/core';
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_HEADER', 'getHeader');
$this->addCallBack('CALLBACK_CORE_GET_LEFT_LINKS', 'getLeftLink');
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getFooter');
$this->addCallBack('CALLBACK_CORE_GET_CONFIG_TABS', 'getUserTabs');
}

/** get layout header */
Expand All @@ -34,7 +35,7 @@ public function getFooter()
$footer .= '<script type="text/javascript" src="'.Zend_Registry::get('webroot').'/modules/'.$this->moduleName.'/public/js/layout/'.$this->moduleName.'.js"></script>';
return $footer;
}

/**
*@method getLeftLink
* will generate a link for this module to be displayed in the main view.
Expand All @@ -45,7 +46,7 @@ public function getLeftLink()
$baseURL = $fc->getBaseUrl();
$moduleWebroot = $baseURL . '/'.$this->moduleName;


if(isset($this->userSession->Dao))
{
$apiComponent = MidasLoader::loadComponent('Api', $this->moduleName);
Expand All @@ -55,10 +56,18 @@ public function getLeftLink()
}
else
{
return array();
return array();
}
}


/** User account tabs */
public function getUserTabs($params)
{
$user = $params['user'];
$fc = Zend_Controller_Front::getInstance();
$moduleWebroot = $fc->getBaseUrl().'/'.$this->moduleName;
return array('Pyslicer' => $moduleWebroot.'/user?userId='.$user->getKey());
}

} //end class
?>
66 changes: 19 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,37 @@ pyslicer
midas viewable python console to interact with slicer


To install and run the twisted based python server that will accept http requests from Midas and
create Slicer jobs in response, first you will need to install a python2.6.
1) To install and run the twisted based python server that will accept http requests from Midas and
create Slicer jobs in response, first you will need to install python (2.6+).

2) Download and extract a Slicer nightly binary, the directory where this is extracted to is SLICER_DIR (where the Slicer exe should be contained in).



Download and extract a Slicer nightly binary, the directory where this is extracted to is SLICER_DIR (where the Slicer exe should be contained in).

Also, in the library/twserver.cfg file, set the path to your slicer exe like so:
3) Update the library/twserver.cfg file:
3a) Set the path to your slicer exe like so:

slicer_path=SLICER_DIR/Slicer

Now change directories into your SLICER_DIR.


cd SLICER_DIR


As of Slicer Nightly Build 10-16-2012, you will no longer need to manually create the include path or copy over pyconfig.h

We will need a pyconfig.h header for python26 in order to install pip. You can get this from an ubuntu python system install of 2.6 at
/usr/include/python2.6



Since we will also be compiling twisted, we will need all headers here, so go ahead and copy them over.

mkdir lib/Python/include
mkdir lib/Python/include/python2.6
cp /usr/include/python2.6/*.h lib/Python/include/python2.6/





Download and install distribute and pip, you will have to replace the path to the python exe with
the path to your installed python 2.6 interpreter exe.

curl http://python-distribute.org/distribute_setup.py > distribute_setup.py
./Slicer --launch /usr/bin/python distribute_setup.py
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py > get_pip.py
./Slicer --launch /usr/bin/python get_pip.py

Now that pip is installed in your Slicer Python, you can run pip to install pydas and the pydas depedencies.

./Slicer --launch SLICER_DIR/lib/Python/bin/pip install pydas
3b) Set the Slicer proxy server URL like so:

You will need to install twisted, but I had trouble with this step:
proxy_url=YOUR_PROXY_URL

./Slicer --launch SLICER_DIR/lib/Python/bin/pip install twisted
4) Install pydas and twisted
4a) Download and install pip

An alternate approach is to download the source of twisted, extract it yourself to TWISTED_DIR, then run this command there:
curl http://python-distribute.org/distribute_setup.py > distribute_setup.py
[sudo] python distribute_setup.py
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py > get_pip.py
[sudo] python get_pip.py

SLICER_DIR/Slicer --no-main-window --python-script setup.py install
4b) Run pip to install pydas and the pydas dependencies.

pip install pydas

4c) Run pip to install twisted:

pip install twisted

Now you could run your twserver.py using your Slicer Python like this :
5) Now you could start twisted server like this :

SLICER_DIR/Slicer --no-main-window --python-script twserver.py
python library/twserver.py

10 changes: 9 additions & 1 deletion constant/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@
define('MIDAS_PYSLICER_SEGMENTATION_PIPELINE', 'segmentation');
define('MIDAS_PYSLICER_VOLUMERENDERING_PIPELINE', 'volumerendering');
define('MIDAS_PYSLICER_REGISTRATION_PIPELINE', 'registration');

define('MIDAS_PYSLICER_PDF_SEGMENTATION_PIPELINE', 'pdfsegmentation');

define('MIDAS_PYSLICER_RELATION_TYPE_INPUT_ITEM', 100);
define('MIDAS_PYSLICER_RELATION_TYPE_INPUT_LABELMAP', 101);
define('MIDAS_PYSLICER_RELATION_TYPE_OUTPUT_SURFACE_MODEL', 102);
define('MIDAS_PYSLICER_RELATION_TYPE_OUTPUT_LABELMAP', 103);

define('MIDAS_PYSLICER_SEGMENTATION_INPUT_COUNT', 1);
define('MIDAS_PYSLICER_SEGMENTATION_OUTPUT_COUNT', 1);
define('MIDAS_PYSLICER_REGISTRATION_INPUT_COUNT', 2);
define('MIDAS_PYSLICER_REGISTRATION_OUTPUT_COUNT', 2);
define('MIDAS_PYSLICER_PDFSEGMENTATION_INPUT_COUNT', 1);
define('MIDAS_PYSLICER_PDFSEGMENTATION_OUTPUT_COUNT', 2);

define('MIDAS_PYSLICER_EXPECTED_INPUTS', 'expectedinputs');
define('MIDAS_PYSLICER_EXPECTED_OUTPUTS', 'expectedoutputs');
Expand Down
150 changes: 150 additions & 0 deletions controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** User settings management */
class Pyslicer_UserController extends Pyslicer_AppController
{
public $_models = array('User');
public $_moduleModels = array('User');

/**
* Shows this user's default settings for Pyslicer module
* @param useAjax If this is an Ajax call
* @param userId userId Id of the user. Must be session user itself.
* @param pipeline Pipeline name.
*/
function indexAction()
{
$this->disableLayout();
$useAjax = $this->_getParam('useAjax');

$userDao = Zend_Registry::get('userSession')->Dao;
$userId = $this->_getParam('userId');
if(isset($userId))
{
$userDao = $this->User->load($userId);
}

if(!$userDao)
{
throw new Zend_Exception('Invalid userId', 404);
}
if(!$this->logged)
{
throw new Zend_Exception('Must be logged in', 403);
}
$pipeline = $this->_getParam('pipeline');
if(!isset($pipeline))
{
$pipeline = MIDAS_PYSLICER_PDF_SEGMENTATION_PIPELINE;
}

$pyslicerUserDao = $this->Pyslicer_User->getByUser($userDao, $pipeline);
if (isset($useAjax) && $useAjax == true)
{
$this->disableView();
$pyslicerUserArr = array();
if ($pyslicerUserDao)
{
$pyslicerUserArr = $pyslicerUserDao->toArray();
}
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Get Pyslicer User settings', 'pyslicerUser' => $pyslicerUserArr));
}
else
{
$this->view->pyslicerUser = $pyslicerUserDao;
}
}

/**
* Create folders for the given pipeline or return existing folders if rootFolderId are same.
* @param userId Id of the user. Must be session user itself.
* @param rootFolderId root folder id for the given pipeline.
* @param pipeline Pipeline name.
*/
function createfoldersAction()
{
$this->disableLayout();
$this->disableView();

$rootFolderId = $this->_getParam('rootFolderId');
$userId = $this->_getParam('userId');
$userDao = Zend_Registry::get('userSession')->Dao;
if(isset($userId))
{
$userDao = $this->User->load($userId);
}
if(!$userDao)
{
throw new Zend_Exception('Invalid userId', 400);
}
if(!$this->logged)
{
throw new Zend_Exception('Must be logged in', 401);
}

$pipeline = $this->_getParam('pipeline');
if(!isset($pipeline))
{
$pipeline = MIDAS_PYSLICER_PDF_SEGMENTATION_PIPELINE;
}
$pyslicerUserDao = $this->Pyslicer_User->createFolders($userDao, $rootFolderId, $pipeline);
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Folders created', 'pyslicerUser' => $pyslicerUserDao));
}

/**
* Delete default Pyslicer settings for this user
* @param userId Id of the user. Must be session user itself.
* @param pipeline Pipeline name.
*/
function deleteAction()
{
$this->disableLayout();
$this->disableView();

$userId = $this->_getParam('userId');
$userDao = Zend_Registry::get('userSession')->Dao;
if(isset($userId))
{
$userDao = $this->User->load($userId);
}
if(!$userDao)
{
throw new Zend_Exception('Invalid userId', 400);
}
if(!$this->logged)
{
throw new Zend_Exception('Must be logged in', 401);
}
$pipeline = $this->_getParam('pipeline');
if(!isset($pipeline))
{
$pipeline = MIDAS_PYSLICER_PDF_SEGMENTATION_PIPELINE;
}

$pyslicerUserDao = $this->Pyslicer_User->getByUser($userDao, $pipeline);
if ($pyslicerUserDao)
{
$this->Pyslicer_User->delete($pyslicerUserDao);
}
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'No default Folders.'));
}
} // end class
?>
Loading