Eliminate C++ DConfig; replace it with a Python compatibility shim

This commit is contained in:
rdb 2018-11-02 22:33:16 +01:00
parent a246acc640
commit 5ac3cf3fc6
23 changed files with 51 additions and 378 deletions

View File

@ -6,8 +6,7 @@ from .ClockDelta import *
from . import DistributedNode
from . import DistributedSmoothNodeBase
from direct.task.Task import cont
config = get_config_showbase()
from direct.showbase import DConfig as config
# This number defines our tolerance for out-of-sync telemetry packets.
# If a packet appears to have originated from more than MaxFuture

View File

@ -0,0 +1,25 @@
"This module contains a deprecated shim emulating the old DConfig API."
__all__ = []
from panda3d.core import (ConfigFlags, ConfigVariableBool, ConfigVariableInt,
ConfigVariableDouble, ConfigVariableString)
def GetBool(sym, default=False):
return ConfigVariableBool(sym, default, "DConfig", ConfigFlags.F_dconfig).value
def GetInt(sym, default=0):
return ConfigVariableInt(sym, default, "DConfig", ConfigFlags.F_dconfig).value
def GetDouble(sym, default=0.0):
return ConfigVariableDouble(sym, default, "DConfig", ConfigFlags.F_dconfig).value
def GetString(sym, default=""):
return ConfigVariableString(sym, default, "DConfig", ConfigFlags.F_dconfig).value
GetFloat = GetDouble

View File

@ -10,8 +10,9 @@ __all__ = ['ShowBase', 'WindowControls']
#import VerboseImport
from panda3d.core import *
from panda3d.direct import get_config_showbase, throw_new_frame, init_app_for_gui
from panda3d.direct import throw_new_frame, init_app_for_gui
from panda3d.direct import storeAccessibilityShortcutKeys, allowAccessibilityShortcutKeys
from . import DConfig
# Register the extension methods for NodePath.
from direct.extensions_native import NodePath_extensions
@ -22,7 +23,7 @@ if sys.version_info >= (3, 0):
import builtins
else:
import __builtin__ as builtins
builtins.config = get_config_showbase()
builtins.config = DConfig
from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify
from .MessengerGlobal import messenger
@ -57,7 +58,7 @@ def exitfunc():
# *seem* to cause anyone any problems.
class ShowBase(DirectObject.DirectObject):
config = get_config_showbase()
config = DConfig
notify = directNotify.newCategory("ShowBase")
def __init__(self, fStartDirect = True, windowType = None):

View File

@ -12,9 +12,8 @@ from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify
from panda3d.core import VirtualFileSystem, Notify, ClockObject, PandaSystem
from panda3d.core import ConfigPageManager, ConfigVariableManager
from panda3d.core import NodePath, PGTop
from panda3d.direct import get_config_showbase
from . import DConfig as config
config = get_config_showbase()
__dev__ = config.GetBool('want-dev', __debug__)
vfs = VirtualFileSystem.getGlobalPtr()

View File

@ -61,14 +61,6 @@ throw_new_frame() {
throw_event("NewFrame");
}
// Returns the configure object for accessing config variables from a
// scripting language.
DConfig &
get_config_showbase() {
static DConfig config_showbase;
return config_showbase;
}
// Initialize the application for making a Gui-based app, such as wx. At the
// moment, this is a no-op except on Mac.
void

View File

@ -38,7 +38,6 @@ EXPCL_DIRECT_SHOWBASE ConfigVariableSearchPath &get_particle_path();
EXPCL_DIRECT_SHOWBASE void throw_new_frame();
EXPCL_DIRECT_SHOWBASE DConfig &get_config_showbase();
EXPCL_DIRECT_SHOWBASE void init_app_for_gui();
// klunky interface since we cant pass array from python->C++

View File

@ -1,21 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file config_dconfig.cxx
* @author drose
* @date 2000-05-15
*/
#include "config_dconfig.h"
#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_DTOOL_DCONFIG)
#error Buildsystem error: BUILDING_DTOOL_DCONFIG not defined
#endif
NotifyCategoryDef(dconfig, "");
NotifyCategoryDef(microconfig, "dconfig");

View File

@ -1,29 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file config_dconfig.h
* @author drose
* @date 2000-05-15
*/
#ifndef CONFIG_DCONFIG_H
#define CONFIG_DCONFIG_H
#ifdef WIN32_VC
/* C4231: extern before template instantiation */
/* MPG - For some reason, this one only works if it's here */
#pragma warning (disable : 4231)
#endif
#include "dtoolbase.h"
#include "notifyCategoryProxy.h"
NotifyCategoryDecl(dconfig, EXPCL_DTOOL_DCONFIG, EXPTP_DTOOL_DCONFIG);
NotifyCategoryDecl(microconfig, EXPCL_DTOOL_DCONFIG, EXPTP_DTOOL_DCONFIG);
#endif

View File

@ -1,42 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file dconfig.I
* @author cary
* @date 2000-03-20
*/
bool DConfig::
GetBool(const std::string &sym, bool def) {
ConfigVariableBool var(sym, def, "DConfig", ConfigFlags::F_dconfig);
return var.get_value();
}
int DConfig::
GetInt(const std::string &sym, int def) {
ConfigVariableInt var(sym, def, "DConfig", ConfigFlags::F_dconfig);
return var.get_value();
}
float DConfig::
GetFloat(const std::string &sym, float def) {
ConfigVariableDouble var(sym, (double)def, "DConfig", ConfigFlags::F_dconfig);
return (float)var.get_value();
}
double DConfig::
GetDouble(const std::string &sym, double def) {
ConfigVariableDouble var(sym, def, "DConfig", ConfigFlags::F_dconfig);
return var.get_value();
}
std::string DConfig::
GetString(const std::string &sym, const std::string &def) {
ConfigVariableString var(sym, def, "DConfig", ConfigFlags::F_dconfig);
return var.get_value();
}

View File

@ -1,14 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file dconfig.cxx
* @author drose
* @date 1999-02-08
*/
#include "dconfig.h"

View File

@ -15,32 +15,7 @@
#define DCONFIG_H
#include "dtoolbase.h"
#include "config_dconfig.h"
#include "configVariableString.h"
#include "configVariableBool.h"
#include "configVariableInt.h"
#include "configVariableDouble.h"
#include "configVariableList.h"
#include "configFlags.h"
/**
* This class emulates the old dconfig-style interface to our Panda config
* system. It exists only to provide backward-compatible support, and it is
* used primarily by Python code. For modern code, use the new
* ConfigVariable* interface instead of this deprecated interface.
*/
class EXPCL_DTOOL_DCONFIG DConfig {
PUBLISHED:
static INLINE bool GetBool(const std::string &sym, bool def = false);
static INLINE int GetInt(const std::string &sym, int def = 0);
static INLINE float GetFloat(const std::string &sym, float def = 0.);
static INLINE double GetDouble(const std::string &sym, double def = 0.);
static INLINE std::string GetString(const std::string &sym, const std::string &def = "");
};
#include "dconfig.I"
#include "notifyCategoryProxy.h"
// These macros are used in each directory to call an initialization function
// at static-init time. These macros may eventually be phased out in favor of

View File

@ -1,3 +0,0 @@
#include "config_dconfig.cxx"
#include "dconfig.cxx"

View File

@ -1,35 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file test_config.cxx
* @author cary
* @date 1998-09-10
*/
#include "dconfig.h"
using std::cout;
using std::endl;
#define SNARF
Configure(test);
std::string foo = test.GetString("user");
std::string path = test.GetString("LD_LIBRARY_PATH");
ConfigureFn(test)
{
cout << "AIEE! Doing work before main()! The sky is falling!" << endl;
}
main()
{
cout << "Testing Configuration functionality:" << endl;
cout << "foo = " << foo << endl;
cout << "path = " << path << endl;
}

View File

@ -1,87 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file test_expand.cxx
* @author cary
* @date 1998-08-31
*/
#include "expand.h"
#include <string>
using std::cout;
using std::endl;
void TestExpandFunction()
{
std::string line;
line = "foo";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
line = "'foo'";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
line = "'$USER'";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
line = "$USER";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
line = "\"$USER\"";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
line = "`ls -l`";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
line = "~";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
line = "~cary";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << Expand::Expand(line) << "'" << endl;
}
void TestExpandClass()
{
std::string line;
line = "foo";
Expand::Expander ex(line);
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex() << "'" << endl;
line = "'foo'";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex(line) << "'" << endl;
line = "'$USER'";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex(line) << "'" << endl;
line = "$USER";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex(line) << "'" << endl;
line = "\"$USER\"";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex(line) << "'" << endl;
line = "`ls -l`";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex(line) << "'" << endl;
line = "~";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex(line) << "'" << endl;
line = "~cary";
cout << "input: '" << line << "'" << endl;
cout << "output: '" << ex(line) << "'" << endl;
}
main()
{
cout << endl << "Testing shell expansion (function version):" << endl;
TestExpandFunction();
cout << endl << "Testing shell expansion (class version):" << endl;
TestExpandClass();
}

View File

@ -1,32 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file test_pfstream.cxx
* @author cary
* @date 1998-08-31
*/
#include "pfstream.h"
#include <string>
void ReadIt(std::istream& ifs) {
std::string line;
while (!ifs.eof()) {
std::getline(ifs, line);
if (line.length() != 0)
std::cout << line << std::endl;
}
}
main()
{
IPipeStream ipfs("ls -l");
ReadIt(ipfs);
}

View File

@ -1,48 +0,0 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file test_searchpath.cxx
* @author cary
* @date 1998-09-01
*/
#include "dSearchPath.h"
// #include "expand.h"
#include <string>
using std::cout;
using std::endl;
void TestSearch()
{
std::string line, path;
// path = ".:~ etc";
path = ". /etc";
// path = Expand::Expand(path);
line = "searchpath.h";
cout << "looking for file '" << line << "' in path '" << path << "': '";
line = DSearchPath::search_path(line, path);
cout << line << "'" << endl;
line = ".cshrc";
cout << "looking for file '" << line << "' in path '" << path << "': '";
line = DSearchPath::search_path(line, path);
cout << line << "'" << endl;
line = "passwd";
cout << "looking for file '" << line << "' in path '" << path << "': '";
line = DSearchPath::search_path(line, path);
cout << line << "'" << endl;
}
main()
{
cout << "Testing search path:" << endl;
TestSearch();
}

View File

@ -2862,6 +2862,20 @@ except ImportError as err:
if "No module named %s" not in str(err):
raise""" % (module, module)
panda_modules_code += """
from direct.showbase import DConfig
def get_config_showbase():
return DConfig
def get_config_express():
return DConfig
getConfigShowbase = get_config_showbase
getConfigExpress = get_config_express
"""
exthelpers_code = """
"This module is deprecated. Import from direct.extensions_native.extension_native_helpers instead."
from direct.extensions_native.extension_native_helpers import *
@ -3412,13 +3426,6 @@ OPTS=['DIR:dtool/src/prc', 'BUILDING:DTOOLCONFIG', 'OPENSSL']
TargetAdd('p3prc_composite1.obj', opts=OPTS, input='p3prc_composite1.cxx')
TargetAdd('p3prc_composite2.obj', opts=OPTS, input='p3prc_composite2.cxx')
#
# DIRECTORY: dtool/src/dconfig/
#
OPTS=['DIR:dtool/src/dconfig', 'BUILDING:DTOOLCONFIG']
TargetAdd('p3dconfig_composite1.obj', opts=OPTS, input='p3dconfig_composite1.cxx')
#
# DIRECTORY: dtool/metalibs/dtoolconfig/
#
@ -3426,7 +3433,6 @@ TargetAdd('p3dconfig_composite1.obj', opts=OPTS, input='p3dconfig_composite1.cxx
OPTS=['DIR:dtool/metalibs/dtoolconfig', 'BUILDING:DTOOLCONFIG']
TargetAdd('p3dtoolconfig_dtoolconfig.obj', opts=OPTS, input='dtoolconfig.cxx')
TargetAdd('libp3dtoolconfig.dll', input='p3dtoolconfig_dtoolconfig.obj')
TargetAdd('libp3dtoolconfig.dll', input='p3dconfig_composite1.obj')
TargetAdd('libp3dtoolconfig.dll', input='p3prc_composite1.obj')
TargetAdd('libp3dtoolconfig.dll', input='p3prc_composite2.obj')
TargetAdd('libp3dtoolconfig.dll', input='libp3dtool.dll')
@ -5640,7 +5646,6 @@ if (RTDIST):
TargetAdd('plugin_standalone_dtoolutil_filename_assist.obj', opts=OPTS, input='filename_assist.mm')
TargetAdd('plugin_standalone_prc_composite1.obj', opts=OPTS, input='p3prc_composite1.cxx')
TargetAdd('plugin_standalone_prc_composite2.obj', opts=OPTS, input='p3prc_composite2.cxx')
TargetAdd('plugin_standalone_dconfig_composite1.obj', opts=OPTS, input='p3dconfig_composite1.cxx')
TargetAdd('plugin_standalone_express_composite1.obj', opts=OPTS, input='p3express_composite1.cxx')
TargetAdd('plugin_standalone_express_composite2.obj', opts=OPTS, input='p3express_composite2.cxx')
TargetAdd('plugin_standalone_downloader_composite1.obj', opts=OPTS, input='p3downloader_composite1.cxx')
@ -5659,7 +5664,6 @@ if (RTDIST):
TargetAdd('p3dembed.exe', input='plugin_standalone_dtoolutil_filename_assist.obj')
TargetAdd('p3dembed.exe', input='plugin_standalone_prc_composite1.obj')
TargetAdd('p3dembed.exe', input='plugin_standalone_prc_composite2.obj')
TargetAdd('p3dembed.exe', input='plugin_standalone_dconfig_composite1.obj')
TargetAdd('p3dembed.exe', input='plugin_standalone_express_composite1.obj')
TargetAdd('p3dembed.exe', input='plugin_standalone_express_composite2.obj')
TargetAdd('p3dembed.exe', input='plugin_standalone_downloader_composite1.obj')
@ -5688,7 +5692,6 @@ if (RTDIST):
TargetAdd('p3dembedw.exe', input='plugin_standalone_dtoolutil_composite2.obj')
TargetAdd('p3dembedw.exe', input='plugin_standalone_prc_composite1.obj')
TargetAdd('p3dembedw.exe', input='plugin_standalone_prc_composite2.obj')
TargetAdd('p3dembedw.exe', input='plugin_standalone_dconfig_composite1.obj')
TargetAdd('p3dembedw.exe', input='plugin_standalone_express_composite1.obj')
TargetAdd('p3dembedw.exe', input='plugin_standalone_express_composite2.obj')
TargetAdd('p3dembedw.exe', input='plugin_standalone_downloader_composite1.obj')

View File

@ -190,11 +190,3 @@ get_verify_dcast() {
return *verify_dcast;
}
// Returns the configure object for accessing config variables from a
// scripting language.
DConfig &
get_config_express() {
static DConfig config_express;
return config_express;
}

View File

@ -54,11 +54,6 @@ extern ConfigVariableBool multifile_always_binary;
extern EXPCL_PANDA_EXPRESS ConfigVariableBool collect_tcp;
extern EXPCL_PANDA_EXPRESS ConfigVariableDouble collect_tcp_interval;
// Expose the Config variable for Python access.
BEGIN_PUBLISH
EXPCL_PANDA_EXPRESS DConfig &get_config_express();
END_PUBLISH
extern EXPCL_PANDA_EXPRESS void init_libexpress();
#endif /* __CONFIG_UTIL_H__ */

View File

@ -22,6 +22,8 @@
#include "dSearchPath.h"
#include "dcast.h"
#include "config_express.h"
#include "configVariableList.h"
#include "configVariableString.h"
#include "executionEnvironment.h"
#include "pset.h"

View File

@ -21,6 +21,7 @@
#include "configVariableInt.h"
#include "configVariableDouble.h"
#include "configVariableList.h"
#include "configVariableString.h"
class DSearchPath;

View File

@ -16,9 +16,11 @@
#include "pandabase.h"
#include "notifyCategoryProxy.h"
#include "configVariableBool.h"
#include "configVariableSearchPath.h"
#include "configVariableEnum.h"
#include "configVariableDouble.h"
#include "configVariableInt.h"
#include "bamEnums.h"
#include "dconfig.h"

View File

@ -19,7 +19,6 @@
#include "dSearchPath.h"
#include "coordinateSystem.h"
#include "dconfig.h"
#include "config_dconfig.h"
#include "string_utils.h"
#include "vector_string.h"
#include "configVariableInt.h"