[PC-BSD Commits] r20103 - users/ken/EasyPBI2
svn at pcbsd.org
svn at pcbsd.org
Thu Nov 1 11:59:12 PDT 2012
Author: kenmoore
Date: 2012-11-01 18:59:11 +0000 (Thu, 01 Nov 2012)
New Revision: 20103
Modified:
users/ken/EasyPBI2/mainGUI.cpp
users/ken/EasyPBI2/modBuild.cpp
users/ken/EasyPBI2/modBuild.h
Log:
Add the ability for the EasyPBI backend to create the resources/[control, tweak-rcconf] files for FreeNAS plugins. It looks like those are not the only two required files though, but also a whole directory full of files for creating/setting up the django interface.
Modified: users/ken/EasyPBI2/mainGUI.cpp
===================================================================
--- users/ken/EasyPBI2/mainGUI.cpp 2012-11-01 14:39:54 UTC (rev 20102)
+++ users/ken/EasyPBI2/mainGUI.cpp 2012-11-01 18:59:11 UTC (rev 20103)
@@ -1208,3 +1208,7 @@
//Add the new types to the UI
ui->line_el_filetype->setText( types.join(",") );
}
+/*------------------------------------------------
+ FREENAS PLUGINS EDITOR OPTIONS
+ -------------------------------------------------
+*/
Modified: users/ken/EasyPBI2/modBuild.cpp
===================================================================
--- users/ken/EasyPBI2/modBuild.cpp 2012-11-01 14:39:54 UTC (rev 20102)
+++ users/ken/EasyPBI2/modBuild.cpp 2012-11-01 18:59:11 UTC (rev 20103)
@@ -1178,3 +1178,118 @@
if( (chk=="true") || (chk=="yes") ){ ret = "YES"; }
return ret;
}
+
+bool ModBuild::writeSampleFreenasControl(){
+ //convert the program name to the proper format
+ QString progname = progStruct[0];
+ progname.toLower().remove(" ").remove("\t").simplified();
+ //Now create the sample file contents
+ QStringList contents;
+ contents << "#!/bin/python";
+ contents << "import os";
+ contents << "import platform";
+ contents << "import re";
+ contents << "import sys";
+ contents << "import stat";
+ contents << "import signal" + QString("\n"); //add an extra line
+ contents << "from flup.server.fcgi import WSGIServer" + QString("\n"); //add extra line
+ contents << "HERE = os.path.abspath(os.path.dirname(__file__))";
+ contents << "sys.path.insert(0, os.path.join(HERE, \"lib/python2.7/site-packages\"))" +QString("\n"); //add extra line
+ contents << "#Define useful variables for this script";
+ contents << progname+"_fcgi_pidfile = \"/var/run/"+progname+"_fcgi_server.pid\"";
+ contents << progname+"_pbi_path = \"/usr/pbi/"+progname+"-\" + platform.machine()";
+ contents << progname+"_etc_path = os.path.join("+progname+"_pbi_path, \"etc\")";
+ contents << progname+"_mnt_path = os.path.join("+progname+"_pbi_path, \"mnt\")";
+ contents << progname+"_www_path = os.path.join("+progname+"_pbi_path, \"www\")";
+ contents << progname+"_opts = os.path.join("+progname+"_etc_path, \"options\")";
+ contents << progname+"_control = \"/usr/local/etc/rc.d/"+progname+"\"" + "\n"; //add extra line
+ contents << "#Define Start function";
+ contents << "def "+progname+"_fcgi_start(args):";
+ contents << " if len(args) < 2:";
+ contents << " return False" + QString("\n"); //add extra line
+ contents << " ip = args[0]";
+ contents << " port = long(args[1])" + QString("\n"); //add extra line
+ contents << " pid = os.fork()";
+ contents << " if pid < 0:";
+ contents << " return False";
+ contents << " if pid != 0:";
+ contents << " sys.exit(0)" +QString("\n"); //add extra line
+ contents << " os.setsid()";
+ contents << " os.environ['DJANGO_SETTINGS_MODULE'] = '"+progname+"UI.settings'";
+ contents << " import django.core.handlers.wsgi";
+ contents << " app = django.core.handlers.wsgi.WSGIHandler()"+QString("\n"); //add extra line
+ contents << " res = False";
+ contents << " with open("+progname+"_fcgi_pidfile, \"wb\") as fp:";
+ contents << " fp.write(str(os.getpid()))";
+ contents << " fp.close()"+QString("\n"); //add extra line
+ contents << " res = WSGIServer(app, bindAddress=(ip, port)).run()" + QString("\n"); //add extra line
+ contents << " return res" + QString("\n"); //add extra line
+ contents << "#Define Stop function";
+ contents << "def "+progname+"_fcgi_stop(args):";
+ contents << " res = False";
+ contents << " if os.access("+progname+"_fcgi_pidfile, os.F_OK):";
+ contents << " with open("+progname+"_fcgi_pidfile, \"r\") as fp:";
+ contents << " pid = long(fp.read())";
+ contents << " fp.close()" +QString("\n"); //add extra line
+ contents << " os.kill(pid, signal.SIGHUP)";
+ contents << " res = True"+QString("\n"); //add extra line
+ contents << " if os.access("+progname+"_fcgi_pidfile, os.F_OK):";
+ contents << " os.unlink("+progname+"_fcgi_pidfile)"+"\n";//add extra line
+ contents << " return res"+QString("\n");//add extra line
+ contents << "#Define Status function";
+ contents << "def "+progname+"_fcgi_status(args):";
+ contents << " res = False";
+ contents << " if os.access("+progname+"_fcgi_pidfile, os.F_OK):";
+ contents << " with open("+progname+"_fcgi_pidfile, \"r\") as fp:";
+ contents << " pid = long(fp.read())";
+ contents << " fp.close()";
+ contents << " res = True"+QString("\n");//add extra line
+ contents << " return res"+QString("\n");//add extra line
+ contents << "#Define Configure function";
+ contents << "def "+progname+"_fcgi_configure(args):";
+ contents << " return True"+QString("\n");//add extra line
+ contents << "#Define Main function";
+ contents << "def main(argc, argv):";
+ contents << " if argc < 2:";
+ contents << " sys.exit(1)"+QString("\n");//add extra line
+ contents << " commands = {";
+ contents << " 'start': "+progname+"_fcgi_start,";
+ contents << " 'stop': "+progname+"_fcgi_stop,";
+ contents << " 'status': "+progname+"_fcgi_status,";
+ contents << " 'configure': "+progname+"_fcgi_configure";
+ contents << " }"+QString("\n");//add extra line
+ contents << " if not commands.has_key(argv[0]):";
+ contents << " sys.exit(1)"+QString("\n");//add extra line
+ contents << " if not commands[argv[0]](argv[1:]):";
+ contents << " sys.exit(1)"+QString("\n");//add extra line
+ contents << " sys.exit(0)"+QString("\n");
+ contents << "if __name__ == '__main__':";
+ contents << " main(len(sys.argv), sys.argv[1:])";
+ //now save the sample file
+ QString filepath = this->path()+"/resources/control";
+ bool status = createFile(filepath, contents);
+ return status;
+
+
+}
+
+bool ModBuild::writeSampleFreenasTweakRC(){
+ //convert the program name to the proper format
+ QString progname = progStruct[0];
+ progname.toLower().remove(" ").remove("\t").simplified();
+ //Now create the sample file contents
+ QStringList contents;
+ contents << "#!/bin/sh\n"; //add an extra line after this
+ contents << "#Setup the temporary program variables";
+ contents << "program_name="+progname;
+ contents << "program_path=/usr/pbi/${program_name}-$(uname -m)"+QString("\n"); //add an extra line
+ contents << "#Perform the modification to /etc/rc.conf";
+ contents << "tmpfile=$(mktemp /tmp/.XXXXXX)";
+ contents << "grep -v '${program_name}_' /etc/rc.conf > ${tmpfile}";
+ contents << "cat ${program_path}/etc/rc.conf >> ${tmpfile}";
+ contents << "mv ${tmpfile} /etc/rc.conf";
+ //now save the sample file
+ QString filepath = this->path()+"/resources/tweak-rcconf";
+ bool status = createFile(filepath, contents);
+ return status;
+}
Modified: users/ken/EasyPBI2/modBuild.h
===================================================================
--- users/ken/EasyPBI2/modBuild.h 2012-11-01 14:39:54 UTC (rev 20102)
+++ users/ken/EasyPBI2/modBuild.h 2012-11-01 18:59:11 UTC (rev 20103)
@@ -66,6 +66,9 @@
QStringList filesAvailable(QString); //get the available files per category
void compressModule(); //package the module for distribution
bool createModuleDir(); //Create/overwrite module directory structure
+ //FreeNAS Plugins
+ bool writeSampleFreenasControl();
+ bool writeSampleFreenasTweakRC();
// --Static functions--
static bool createFile(QString,QStringList);
More information about the Commits
mailing list