@@ -126,10 +126,8 @@ class PyCodeBuilder {
126126WsjcppJsonRpc20ExportCliPython::WsjcppJsonRpc20ExportCliPython (
127127 const std::string &sExportDir ,
128128 const std::string &sPackageName
129- ) {
129+ ) : WsjcppJsonRpc20ExportCliBase( sExportDir , sPackageName ) {
130130 TAG = " WsjcppJsonRpc20ExportCliPython" ;
131- m_sExportDir = WsjcppCore::doNormalizePath (sExportDir );
132- m_sPackageName = sPackageName ;
133131 m_sAuthorName = " Unknown" ;
134132 m_sAuthorEmail = " unknown" ;
135133 m_sAppName = " unknown" ;
@@ -235,7 +233,7 @@ bool WsjcppJsonRpc20ExportCliPython::doExportLib() {
235233
236234bool WsjcppJsonRpc20ExportCliPython::exportPrepareDirs () {
237235 std::vector<std::string> vCreateDirs;
238- std::vector<std::string> vSplited = WsjcppCore::split (m_sExportDir , " /" );
236+ std::vector<std::string> vSplited = WsjcppCore::split (this -> getExportDir () , " /" );
239237 std::string sExportDir = " " ;
240238 for (int i = 0 ; i < vSplited.size (); i++) {
241239 if (i > 0 ) {
@@ -245,7 +243,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportPrepareDirs() {
245243 sExportDir = WsjcppCore::doNormalizePath (sExportDir );
246244 vCreateDirs.push_back (sExportDir );
247245 }
248- sExportDir = WsjcppCore::doNormalizePath (sExportDir + " /" + m_sPackageName );
246+ sExportDir = WsjcppCore::doNormalizePath (sExportDir + " /" + this -> getPackageName () );
249247 vCreateDirs.push_back (sExportDir );
250248
251249 for (int i = 0 ; i < vCreateDirs.size (); i++) {
@@ -267,20 +265,20 @@ bool WsjcppJsonRpc20ExportCliPython::exportPrepareDirs() {
267265// ---------------------------------------------------------------------
268266
269267bool WsjcppJsonRpc20ExportCliPython::prepareReadmeMdIfNeed () {
270- std::string sReadmeMd = m_sExportDir + " /README.md" ;
268+ std::string sReadmeMd = this -> getExportDir () + " /README.md" ;
271269 if (!WsjcppCore::fileExists (sReadmeMd )) {
272270 std::string sContentReadme =
273- " #" + m_sPackageName + " \n\n "
271+ " #" + this -> getPackageName () + " \n\n "
274272 + m_sClassName + " Python Library for " + m_sAppName + " \n\n "
275273 + " ## Install \n\n "
276274 + " ```\n "
277- + " $ pip3 install " + m_sPackageName + " --upgrade\n "
275+ + " $ pip3 install " + this -> getPackageName () + " --upgrade\n "
278276 + " ```\n\n "
279277 + " ## Example code\n\n "
280278 + " ```\n "
281279 + " #!/usr/bin/env python3\n "
282280 + " # -*- coding: utf-8 -*-\n "
283- + " from " + m_sPackageName + " import " + m_sClassName + " \n\n "
281+ + " from " + this -> getPackageName () + " import " + m_sClassName + " \n\n "
284282 + " client = " + m_sClassName + " (\" ws://host/ws-api/\" )\n\n "
285283 + " resp = client.server_api({})\n\n "
286284 + " print(resp)\n "
@@ -296,7 +294,7 @@ bool WsjcppJsonRpc20ExportCliPython::prepareReadmeMdIfNeed() {
296294
297295bool WsjcppJsonRpc20ExportCliPython::exportSetupPy () {
298296 std::ofstream setupPy;
299- std::string sFilename = m_sExportDir + " /setup.py" ;
297+ std::string sFilename = this -> getExportDir () + " /setup.py" ;
300298 WsjcppLog::info (TAG, " Prepare setup.py " + sFilename );
301299
302300 // https://packaging.python.org/tutorials/packaging-projects/
@@ -307,9 +305,9 @@ bool WsjcppJsonRpc20ExportCliPython::exportSetupPy() {
307305 " long_description = fh.read()\n "
308306 " \n "
309307 " setuptools.setup(\n "
310- " name='" + m_sPackageName + " ',\n "
308+ " name='" + this -> getPackageName () + " ',\n "
311309 " version='" + m_sAppVersion + " ',\n "
312- " packages=['" + m_sPackageName + " '],\n "
310+ " packages=['" + this -> getPackageName () + " '],\n "
313311 " install_requires=['websocket-client>=0.56.0', 'requests>=2.21.0'],\n "
314312 " keywords=['" + WsjcppCore::join (m_vKeywords, " ', '" ) + " '],\n "
315313 " author='" + m_sAuthorName + " ',\n "
@@ -345,7 +343,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportSetupPy() {
345343bool WsjcppJsonRpc20ExportCliPython::exportAPImd () {
346344
347345 std::ofstream apimd;
348- std::string sFilename = m_sExportDir + " /API.md" ;
346+ std::string sFilename = this -> getExportDir () + " /API.md" ;
349347 WsjcppLog::info (TAG, " Prepare API.md " + sFilename );
350348
351349 apimd.open (sFilename );
@@ -358,7 +356,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportAPImd() {
358356 apimd << " * Date: " << WsjcppCore::formatTimeForWeb (nSec) << " \n\n " ;
359357 apimd << " Example connect/disconnect:\n "
360358 << " ```\n "
361- << " from " + m_sPackageName + " import " + m_sClassName + " \n\n "
359+ << " from " + getPackageName () + " import " + m_sClassName + " \n\n "
362360 << " client = " + m_sClassName + " ('ws://host:1234')\n "
363361 << " ... \n "
364362 << " client.close()\n "
@@ -426,7 +424,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportAPImd() {
426424// ---------------------------------------------------------------------
427425
428426bool WsjcppJsonRpc20ExportCliPython::exportInitPy () {
429- std::string sFilename = m_sExportDir + " /" + m_sPackageName + " /__init__.py" ;
427+ std::string sFilename = this -> getExportDir () + " /" + this -> getPackageName () + " /__init__.py" ;
430428 WsjcppLog::info (TAG, " Prepare __init__.py " + sFilename );
431429 std::ofstream __init__;
432430 __init__.open (sFilename );
@@ -470,8 +468,10 @@ void exportCliPythonAddCheckDataTypeOfParam(
470468 }
471469};
472470
471+ // ---------------------------------------------------------------------
472+
473473bool WsjcppJsonRpc20ExportCliPython::exportClientPy () {
474- std::string sFilename = m_sExportDir + " /" + m_sPackageName + " /" + m_sClassName + " .py" ;
474+ std::string sFilename = this -> getExportDir () + " /" + this -> getPackageName () + " /" + m_sClassName + " .py" ;
475475 WsjcppLog::info (TAG, " Prepare " + m_sClassName + " .py: " + sFilename );
476476
477477 std::ofstream clientpy;
@@ -534,6 +534,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportClientPy() {
534534 .sub (" def getToken(self):" )
535535 .add (" return self.__token" )
536536 .end ()
537+ .add (" " )
537538 .sub (" def setToken(self, token):" )
538539 .sub (" if self.__token is None:" )
539540 .add (" self.__token = token" )
0 commit comments