Initial PoC of a CherryPy app integrate with the runtime.

Upon startup, the runtime will attempt to locate pgAdmin4.py in a
number of different relative locations. Once found, it will execute
it in a new thread. The main window is then created and the brower's
initial page is set to the root of the CherryPy server. At present,
that's http://127.0.0.1:8080.
This commit is contained in:
Dave Page
2013-06-21 23:21:11 +01:00
parent 1afc31c657
commit 28f45ea9f9
56 changed files with 21993 additions and 47 deletions

79
runtime/Server.cpp Normal file
View File

@@ -0,0 +1,79 @@
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// Server.cpp - Thread in which the web server will run.
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin4.h"
// Must be before QT
#include <Python.h>
// QT headers
#include <QMessageBox>
// App headers
#include "Server.h"
Server::Server()
{
// Initialise Python
Py_SetProgramName(PGA_APPNAME.toUtf8().data());
Py_Initialize();
}
Server::~Server()
{
// Shutdown Python
Py_Finalize();
}
bool Server::Init()
{
// Find the webapp
QStringList paths;
paths.append("../web/"); // Windows/Linux source tree
paths.append("../../../../web/"); // Mac source tree (in the app bundle)
paths.append(""); // Should be last!
for (int i = 0; i < paths.size(); ++i)
{
QDir dir(QCoreApplication::applicationDirPath() + "/" + paths[i]);
m_appfile = dir.canonicalPath() + "/pgAdmin4.py";
if (QFile::exists(m_appfile))
{
qDebug() << "Webapp path: " << m_appfile;
break;
}
}
if (!QFile::exists(m_appfile))
{
setError("Failed to locate pgAdmin4.py, terminating server thread.");
return false;
}
return true;
}
void Server::run()
{
// Open the application code and run it.
FILE *cp = fopen(m_appfile.toUtf8().data(), "r");
if (!cp)
{
setError("Failed to open the application file: " + m_appfile + ", server thread exiting.");
return;
}
if (PyRun_SimpleFile(cp, m_appfile.toUtf8().data()) != 0)
setError("Failed to launch the application server, server thread exiting.");
fclose(cp);
}