Skip to content

Commit

Permalink
Merge branch 'devel' for releasing '3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrenfeu committed Feb 12, 2016
2 parents e62336c + 00c2c15 commit 90db5dd
Show file tree
Hide file tree
Showing 503 changed files with 52,216 additions and 28,590 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Configuration files
config.local/
config/*_config.inc
config/hrm.conf
resources/hrmd.plist
user/login_user.inc

# Customization files
images/hrm_custom.ico
images/logo_custom.png
css/custom.css

# IDE project settings
/nbproject/
/.idea/
Expand Down
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# if nothing is requested explicitly, go to the login page:
DirectoryIndex login.php

# prevent serving git stuff:
RedirectMatch 404 /\.git
2 changes: 2 additions & 0 deletions aberration_correction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

if ( $_SESSION['setting']->isSted() || $_SESSION['setting']->isSted3D()) {
$back = "sted_parameters.php";
} else if ( $_SESSION['setting']->isSpim()) {
$back = "spim_parameters.php";
} else {
$back = "capturing_parameter.php";
}
Expand Down
99 changes: 99 additions & 0 deletions bin/hrm_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python

"""Helper module to parse the HRM (shell style) config file.
Usually, the config is located at /etc/hrm.conf and written in shell syntax as
this file simply gets sourced by the bash init script and other shell based
tools.
This module is not meant to be executed directly and doesn't do anything in
this case.
"""

# NOTE:
# It might be worth checking out the solution described on stackoverflow [1]
# using an approach based on a real shell subprocess like this:
"""
>>> command = ['bash', '-c', 'source init_env && env']
>>> proc = subprocess.Popen(command, stdout = subprocess.PIPE)
>>> for line in proc.stdout:
... (key, _, value) = line.partition("=")
... os.environ[key] = value
>>> proc.communicate()
"""
# [1]: http://stackoverflow.com/questions/3503719/


import shlex
import sys


def parse_hrm_conf(filename):
"""Assemble a dict from the HRM config file (shell syntax).
Parameters
==========
filename: str - the filename to parse
Returns
=======
config: dict
Example
=======
{
'HRM_DATA': '/export/hrm_data',
'HRM_DEST': 'dst',
'HRM_HOME': '/var/www/hrm',
'HRM_LOG': '/var/log/hrm',
'HRM_SOURCE': 'src',
'OMERO_HOSTNAME': 'omero.mynetwork.xy',
'OMERO_PKG': '/opt/OMERO/OMERO.server',
'OMERO_PORT': '4064',
'PHP_CLI': '/usr/local/php/bin/php',
'SUSER': 'hrm'
}
"""
config = dict()
body = file(filename, 'r').read()
lexer = shlex.shlex(body)
lexer.wordchars += '-./'
while True:
token = lexer.get_token()
if token is None or token == '':
break
# it's valid sh syntax to use a semicolon to join lines, so accept it:
if token == ';':
continue
# we assume entries of the following form:
# KEY="some-value"
key = token
try:
equals = lexer.get_token()
assert equals == '='
except AssertionError:
raise SyntaxError(
"Can't parse %s, invalid syntax in line %s "
"(expected '=', found '%s')." %
(filename, lexer.lineno, equals))
value = lexer.get_token()
value = value.replace('"', '') # remove double quotes
value = value.replace("'", '') # remove single quotes
config[key] = value
return config


def check_hrm_conf(config):
"""Check the config dict for required entries."""
required = ['OMERO_PKG', 'OMERO_HOSTNAME']
for entry in required:
if entry not in config:
raise SyntaxError('Missing "%s" in the HRM config file.' % entry)


if __name__ == "__main__":
print __doc__
sys.exit(1)

CONFIG = parse_hrm_conf('/etc/hrm.conf')
check_hrm_conf(CONFIG)
Loading

0 comments on commit 90db5dd

Please sign in to comment.