Skip to content

Commit d6d37ae

Browse files
committed
Moved methods setAuthor* and setClassName to Export Cli Base class
1 parent 9282733 commit d6d37ae

8 files changed

+86
-89
lines changed

example-of-exported/py3/API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Automatically generated by wsjcpp-jsonrpc20.
44
* Version: v0.0.4
5-
* Date: Wed, 07 Oct 2020 02:05:13 GMT
5+
* Date: Wed, 07 Oct 2020 17:03:09 GMT
66

77
Example connect/disconnect:
88
```

example-of-exported/py3/libwsjcppjson20client/SomeClient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33
### This file was automatically generated by wsjcpp-jsonrpc20
44
### Version: v0.0.4
5-
### Date: Wed, 07 Oct 2020 02:05:13 GMT
5+
### Date: Wed, 07 Oct 2020 17:03:09 GMT
66

77
import asyncio
88
import websocket

src/wsjcpp_jsonrpc20_export_cli_base.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ WsjcppJsonRpc20ExportCliBase::WsjcppJsonRpc20ExportCliBase(
2222
TAG = "WsjcppJsonRpc20ExportCliBase";
2323
m_sExportDir = WsjcppCore::doNormalizePath(sExportDir);
2424
m_sPackageName = sPackageName;
25+
m_sAppName = "unknown";
26+
m_sAppVersion = "unknown";
27+
m_sAuthorName = "Unknown";
28+
m_sAuthorEmail = "unknown";
29+
m_sClassName = "Unknown";
2530
}
2631

2732
// ---------------------------------------------------------------------
@@ -63,4 +68,40 @@ std::string WsjcppJsonRpc20ExportCliBase::getAppVersion() const {
6368
return m_sAppVersion;
6469
}
6570

71+
// ---------------------------------------------------------------------
72+
73+
void WsjcppJsonRpc20ExportCliBase::setAuthorName(const std::string &sAuthorName) {
74+
m_sAuthorName = sAuthorName;
75+
}
76+
77+
// ---------------------------------------------------------------------
78+
79+
std::string WsjcppJsonRpc20ExportCliBase::getAuthorName() const {
80+
return m_sAuthorName;
81+
}
82+
83+
// ---------------------------------------------------------------------
84+
85+
void WsjcppJsonRpc20ExportCliBase::setAuthorEmail(const std::string &sAuthorEmail) {
86+
m_sAuthorEmail = sAuthorEmail;
87+
}
88+
89+
// ---------------------------------------------------------------------
90+
91+
std::string WsjcppJsonRpc20ExportCliBase::getAuthorEmail() const {
92+
return m_sAuthorEmail;
93+
}
94+
95+
// ---------------------------------------------------------------------
96+
97+
void WsjcppJsonRpc20ExportCliBase::setClassName(const std::string &sClassName) {
98+
m_sClassName = sClassName;
99+
}
100+
101+
// ---------------------------------------------------------------------
102+
103+
std::string WsjcppJsonRpc20ExportCliBase::getClassName() const {
104+
return m_sClassName;
105+
}
106+
66107
// ---------------------------------------------------------------------

src/wsjcpp_jsonrpc20_export_cli_base.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class WsjcppJsonRpc20ExportCliBase {
1818
std::string getAppName() const;
1919
void setAppVersion(const std::string &sAppVersion);
2020
std::string getAppVersion() const;
21+
void setAuthorName(const std::string &sAuthorName);
22+
std::string getAuthorName() const;
23+
void setAuthorEmail(const std::string &sAuthorEmail);
24+
std::string getAuthorEmail() const;
25+
void setClassName(const std::string &sClassName);
26+
std::string getClassName() const;
2127

2228
virtual bool doExportLib() = 0;
2329

@@ -29,6 +35,11 @@ class WsjcppJsonRpc20ExportCliBase {
2935
std::string m_sPackageName;
3036
std::string m_sAppName;
3137
std::string m_sAppVersion;
38+
39+
std::string m_sClassName;
40+
std::string m_sAuthorName;
41+
std::string m_sAuthorEmail;
42+
3243
};
3344

3445
#endif // WSJCPP_JSONRPC20_EXPORT_CLI_BASE_H

src/wsjcpp_jsonrpc20_export_cli_python.cpp

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -128,32 +128,11 @@ WsjcppJsonRpc20ExportCliPython::WsjcppJsonRpc20ExportCliPython(
128128
const std::string &sPackageName
129129
) : WsjcppJsonRpc20ExportCliBase(sExportDir, sPackageName) {
130130
TAG = "WsjcppJsonRpc20ExportCliPython";
131-
m_sAuthorName = "Unknown";
132-
m_sAuthorEmail = "unknown";
133-
m_sClassName = "Unknown";
134131
m_sUrl = "none";
135132
}
136133

137134
// ---------------------------------------------------------------------
138135

139-
void WsjcppJsonRpc20ExportCliPython::setAuthorName(const std::string &sAuthorName) {
140-
m_sAuthorName = sAuthorName;
141-
}
142-
143-
// ---------------------------------------------------------------------
144-
145-
void WsjcppJsonRpc20ExportCliPython::setAuthorEmail(const std::string &sAuthorEmail) {
146-
m_sAuthorEmail = sAuthorEmail;
147-
}
148-
149-
// ---------------------------------------------------------------------
150-
151-
void WsjcppJsonRpc20ExportCliPython::setClassName(const std::string &sClassName) {
152-
m_sClassName = sClassName;
153-
}
154-
155-
// ---------------------------------------------------------------------
156-
157136
void WsjcppJsonRpc20ExportCliPython::setUrl(const std::string &sUrl) {
158137
m_sUrl = sUrl;
159138
}
@@ -252,7 +231,7 @@ bool WsjcppJsonRpc20ExportCliPython::prepareReadmeMdIfNeed() {
252231
if (!WsjcppCore::fileExists(sReadmeMd)) {
253232
std::string sContentReadme =
254233
"#" + this->getPackageName() + "\n\n"
255-
+ m_sClassName + " Python Library for " + this->getAppName() + "\n\n"
234+
+ this->getClassName() + " Python Library for " + this->getAppName() + "\n\n"
256235
+ "## Install \n\n"
257236
+ "```\n"
258237
+ "$ pip3 install " + this->getPackageName() + " --upgrade\n"
@@ -261,8 +240,8 @@ bool WsjcppJsonRpc20ExportCliPython::prepareReadmeMdIfNeed() {
261240
+ "```\n"
262241
+ "#!/usr/bin/env python3\n"
263242
+ "# -*- coding: utf-8 -*-\n"
264-
+ "from " + this->getPackageName() + " import " + m_sClassName + "\n\n"
265-
+ "client = " + m_sClassName + "(\"ws://host/ws-api/\")\n\n"
243+
+ "from " + this->getPackageName() + " import " + this->getClassName() + "\n\n"
244+
+ "client = " + this->getClassName() + "(\"ws://host/ws-api/\")\n\n"
266245
+ "resp = client.server_api({})\n\n"
267246
+ "print(resp)\n"
268247
+ "```\n\n"
@@ -293,9 +272,9 @@ bool WsjcppJsonRpc20ExportCliPython::exportSetupPy() {
293272
" packages=['" + this->getPackageName() + "'],\n"
294273
" install_requires=['websocket-client>=0.56.0', 'requests>=2.21.0'],\n"
295274
" keywords=['" + WsjcppCore::join(m_vKeywords, "', '") + "'],\n"
296-
" author='" + m_sAuthorName + "',\n"
297-
" author_email='" + m_sAuthorEmail + "',\n"
298-
" description='" + m_sClassName + " Python Library for " + this->getAppName() + "',\n"
275+
" author='" + this->getAuthorName() + "',\n"
276+
" author_email='" + this->getAuthorEmail() + "',\n"
277+
" description='" + this->getClassName() + " Python Library for " + this->getAppName() + "',\n"
299278
" long_description=long_description,\n"
300279
" long_description_content_type='text/markdown',\n"
301280
" url='" + m_sUrl + "',\n"
@@ -333,14 +312,14 @@ bool WsjcppJsonRpc20ExportCliPython::exportAPImd() {
333312

334313
long nSec = WsjcppCore::getCurrentTimeInSeconds();
335314

336-
apimd << "# " + m_sClassName + " Python Library \n\n";
315+
apimd << "# " + this->getClassName() + " Python Library \n\n";
337316
apimd << "Automatically generated by " << this->getAppName() << ". \n";
338317
apimd << "* Version: " << this->getAppVersion() << "\n";
339318
apimd << "* Date: " << WsjcppCore::formatTimeForWeb(nSec) << "\n\n";
340319
apimd << "Example connect/disconnect:\n"
341320
<< "```\n"
342-
<< "from " + getPackageName() + " import " + m_sClassName + " \n\n"
343-
<< "client = " + m_sClassName + "('ws://host:1234')\n"
321+
<< "from " + getPackageName() + " import " + this->getClassName() + " \n\n"
322+
<< "client = " + this->getClassName() + "('ws://host:1234')\n"
344323
<< " ... \n"
345324
<< "client.close()\n"
346325
<< "```\n";
@@ -411,7 +390,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportInitPy() {
411390
WsjcppLog::info(TAG, "Prepare __init__.py " + sFilename);
412391
std::ofstream __init__;
413392
__init__.open (sFilename);
414-
__init__ << "from ." << m_sClassName << " import " << m_sClassName << "\n";
393+
__init__ << "from ." << this->getClassName() << " import " << this->getClassName() << "\n";
415394
WsjcppLog::ok(TAG, "Done: " + sFilename);
416395
return true;
417396
}
@@ -454,8 +433,8 @@ void exportCliPythonAddCheckDataTypeOfParam(
454433
// ---------------------------------------------------------------------
455434

456435
bool WsjcppJsonRpc20ExportCliPython::exportClientPy() {
457-
std::string sFilename = this->getExportDir() + "/" + this->getPackageName() + "/" + m_sClassName + ".py";
458-
WsjcppLog::info(TAG, "Prepare " + m_sClassName + ".py: " + sFilename);
436+
std::string sFilename = this->getExportDir() + "/" + this->getPackageName() + "/" + this->getClassName() + ".py";
437+
WsjcppLog::info(TAG, "Prepare " + this->getClassName() + ".py: " + sFilename);
459438

460439
std::ofstream clientpy;
461440
clientpy.open (sFilename);
@@ -476,7 +455,7 @@ bool WsjcppJsonRpc20ExportCliPython::exportClientPy() {
476455
.add("import select")
477456
.add("import time")
478457
.add("")
479-
.sub("class " + m_sClassName + ":")
458+
.sub("class " + this->getClassName() + ":")
480459
.add("__ws = None")
481460
.add("__url = None")
482461
.add("__cli_version = '" + this->getAppVersion() + "'")
@@ -732,14 +711,14 @@ bool WsjcppJsonRpc20ExportCliPython::exportClientPy() {
732711
if (paramDef.isRequired()) {
733712
builder
734713
.sub("if " + sParamName + " is None: ")
735-
.add("raise Exception('Parameter \"" + sParamName + "\" expected (lib: " + m_sClassName + "." + sMethod + ")')")
714+
.add("raise Exception('Parameter \"" + sParamName + "\" expected (lib: " + this->getClassName() + "." + sMethod + ")')")
736715
.end();
737-
exportCliPythonAddCheckDataTypeOfParam(builder, paramDef, m_sClassName, sMethod);
716+
exportCliPythonAddCheckDataTypeOfParam(builder, paramDef, this->getClassName(), sMethod);
738717
builder.add("reqJson['params']['" + sParamName + "'] = " + sParamName);
739718
} else if (paramDef.isOptional()) {
740719
builder
741720
.sub("if " + sParamName + " != None: ");
742-
exportCliPythonAddCheckDataTypeOfParam(builder, paramDef, m_sClassName, sMethod);
721+
exportCliPythonAddCheckDataTypeOfParam(builder, paramDef, this->getClassName(), sMethod);
743722
builder
744723
.add("reqJson['params']['" + sParamName + "'] = " + sParamName)
745724
.end();

src/wsjcpp_jsonrpc20_export_cli_python.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class WsjcppJsonRpc20ExportCliPython : public WsjcppJsonRpc20ExportCliBase {
1111
const std::string &sExportDir,
1212
const std::string &sPackageName
1313
);
14-
void setAuthorName(const std::string &sAuthorName);
15-
void setAuthorEmail(const std::string &sAuthorEmail);
16-
void setClassName(const std::string &sClassName);
1714
void setUrl(const std::string &sUrl);
1815
void setDownloadUrl(const std::string &sDownloadUrl);
1916
void setKeywords(const std::vector<std::string> &vKeywords);
@@ -22,9 +19,7 @@ class WsjcppJsonRpc20ExportCliPython : public WsjcppJsonRpc20ExportCliBase {
2219

2320
virtual bool doExportLib() override;
2421
private:
25-
std::string m_sAuthorName;
26-
std::string m_sAuthorEmail;
27-
std::string m_sClassName;
22+
2823
std::string m_sUrl;
2924
std::string m_sDownloadUrl;
3025
std::vector<std::string> m_vKeywords;

0 commit comments

Comments
 (0)