<s> from __future__ import print_function , unicode_literals <EOL> import os <EOL> import time <EOL> from collections import OrderedDict <EOL> from weblab . util import data_filename <EOL> import flask_admin <EOL> def weblab_httpd_config_generate ( directory ) : <EOL> print ( "<STR_LIT>" , end = '<STR_LIT>' ) <EOL> result = httpd_config_generate ( directory ) <EOL> print ( "<STR_LIT>" ) <EOL> return result <EOL> def httpd_config_generate ( directory ) : <EOL> debugging_variables = { } <EOL> execfile ( os . path . join ( directory , '<STR_LIT>' ) , debugging_variables ) <EOL> ports = debugging_variables . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) <EOL> base_url = debugging_variables . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if base_url in ( '<STR_LIT>' , '<STR_LIT:/>' ) : <EOL> base_url = '<STR_LIT>' <EOL> static_directories = OrderedDict ( ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = data_filename ( '<STR_LIT>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> flask_admin_static = os . path . join ( os . path . dirname ( flask_admin . __file__ ) , '<STR_LIT>' ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = flask_admin_static . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = data_filename ( '<STR_LIT>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = data_filename ( '<STR_LIT>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = data_filename ( '<STR_LIT>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = data_filename ( '<STR_LIT>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = data_filename ( '<STR_LIT>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> static_directories [ base_url + '<STR_LIT>' ] = os . path . abspath ( os . path . join ( directory , '<STR_LIT>' ) ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> files = { } <EOL> apache_contents = _apache_generation ( directory , base_url , ports , static_directories ) <EOL> files [ '<STR_LIT>' ] = _set_contents ( directory , '<STR_LIT>' , apache_contents ) <EOL> simple_httpd_contents = _simple_httpd_generation ( directory , base_url , ports , static_directories ) <EOL> files [ '<STR_LIT>' ] = _set_contents ( directory , '<STR_LIT>' , simple_httpd_contents ) <EOL> return files <EOL> def _set_contents ( directory , filename , new_contents ) : <EOL> original_path = os . path . join ( directory , filename ) <EOL> destination_path = os . path . join ( directory , filename + "<STR_LIT>" + time . strftime ( "<STR_LIT>" ) ) <EOL> if os . path . exists ( original_path ) : <EOL> original_contents = open ( original_path ) . read ( ) <EOL> open ( destination_path , '<STR_LIT:w>' ) . write ( original_contents ) <EOL> open ( original_path , '<STR_LIT:w>' ) . write ( new_contents ) <EOL> return os . path . abspath ( original_path ) <EOL> def _apache_generation ( directory , base_url , ports , static_directories ) : <EOL> apache_conf = ( <EOL> "<STR_LIT:\n>" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" ) <EOL> for static_url , static_directory in static_directories . items ( ) : <EOL> apache_conf += """<STR_LIT>""" % dict ( static_url = static_url , static_directory = static_directory ) <EOL> apache_conf += ( <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" ) <EOL> previous = [ ] <EOL> for static_directory in static_directories . values ( ) : <EOL> if static_directory in previous : <EOL> continue <EOL> previous . append ( static_directory ) <EOL> apache_conf += ( """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" ) % dict ( static_directory = static_directory ) <EOL> apache_conf += ( <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT:\n>""" ) <EOL> for static_url , static_directory in static_directories . items ( ) : <EOL> apache_conf += """<STR_LIT>""" % dict ( static_url = static_url ) <EOL> apache_conf += ( <EOL> """<STR_LIT:\n>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> "<STR_LIT:\n>" ) <EOL> apache_conf += "<STR_LIT:\n>" <EOL> apache_conf += """<STR_LIT>""" <EOL> for pos , port in enumerate ( ports ) : <EOL> d = { '<STR_LIT:port>' : port , '<STR_LIT>' : '<STR_LIT>' % ( pos + <NUM_LIT:1> ) , '<STR_LIT:root>' : '<STR_LIT>' } <EOL> apache_conf += """<STR_LIT>""" % d <EOL> apache_conf += """<STR_LIT>""" <EOL> apache_img_dir = '<STR_LIT>' <EOL> apache_root_without_slash = base_url [ <NUM_LIT:1> : ] if base_url . startswith ( '<STR_LIT:/>' ) else base_url <EOL> server_conf_dict = { '<STR_LIT:root>' : base_url , '<STR_LIT>' : apache_root_without_slash . replace ( '<STR_LIT:/>' , '<STR_LIT:_>' ) , <EOL> '<STR_LIT>' : os . path . abspath ( directory ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) , <EOL> '<STR_LIT>' : data_filename ( '<STR_LIT>' ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) } <EOL> apache_conf = apache_conf % server_conf_dict <EOL> apache_conf_path = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return apache_conf <EOL> def _simple_httpd_generation ( directory , base_url , ports , static_directories ) : <EOL> proxy_paths = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> for key , directory in static_directories . items ( ) : <EOL> proxy_paths . append ( ( key , '<STR_LIT>' . format ( directory ) ) ) <EOL> proxy_path = "<STR_LIT>" <EOL> for pos , port in enumerate ( ports ) : <EOL> d = { '<STR_LIT:port>' : port , '<STR_LIT>' : '<STR_LIT>' % ( pos + <NUM_LIT:1> ) , '<STR_LIT:root>' : '<STR_LIT>' } <EOL> proxy_path += '<STR_LIT>' % d <EOL> proxy_paths . append ( ( '<STR_LIT>' , proxy_path ) ) <EOL> proxy_paths . append ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> proxy_paths . append ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if base_url in ( '<STR_LIT>' , '<STR_LIT:/>' ) : <EOL> root = '<STR_LIT>' <EOL> else : <EOL> root = base_url <EOL> apache_img_dir = '<STR_LIT>' <EOL> server_conf_dict = { '<STR_LIT:root>' : root , <EOL> '<STR_LIT>' : os . path . abspath ( directory ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> } <EOL> proxy_paths = eval ( repr ( proxy_paths ) % server_conf_dict ) <EOL> proxy_paths_str = "<STR_LIT>" <EOL> for proxy_path in proxy_paths : <EOL> proxy_paths_str += "<STR_LIT>" % repr ( proxy_path ) <EOL> proxy_paths_str += "<STR_LIT>" <EOL> return proxy_paths_str <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> httpd_config_generate ( "<STR_LIT>" ) </s>
