Skip to content

Commit 3b5894e

Browse files
committed
Convert pickle script
1 parent 4c31374 commit 3b5894e

File tree

7 files changed

+74
-34
lines changed

7 files changed

+74
-34
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python2
2+
3+
import sys
4+
import pickle
5+
import argparse
6+
7+
if __name__ == "__main__":
8+
argc = len(sys.argv)
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument('data', help='pickle encode/decode hexed string', type=str)
12+
parser.add_argument('--encode', action='store_true', help='pickle encode string')
13+
parser.add_argument('--decode', action='store_false', help='pickle decode string')
14+
args = parser.parse_args()
15+
16+
hexed_data = args.data
17+
unhexed = hexed_data.replace('x', '') # 1122
18+
raw_pickle = unhexed.decode('hex')
19+
20+
try:
21+
if args.encode:
22+
pickle_str = pickle.dumps(raw_pickle)
23+
else:
24+
pickle_str = pickle.loads(raw_pickle)
25+
except Exception as ex:
26+
sys.exit(1)
27+
28+
result_str = ''.join('\\x{:02x}'.format(ord(x)) for x in pickle_str)
29+
print(result_str)
30+
sys.exit(0)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python2
2+
3+
import sys
4+
import pickle
5+
import argparse
6+
7+
if __name__ == "__main__":
8+
argc = len(sys.argv)
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument('data', help='pickle encode/decode hexed string', type=str)
12+
parser.add_argument('--encode', action='store_true', help='pickle encode string')
13+
parser.add_argument('--decode', action='store_false', help='pickle decode string')
14+
args = parser.parse_args()
15+
16+
hexed_data = args.data
17+
unhexed = hexed_data.replace('x', '') # 1122
18+
raw_pickle = unhexed.decode('hex')
19+
20+
try:
21+
if args.encode:
22+
pickle_str = pickle.dumps(raw_pickle)
23+
else:
24+
pickle_str = pickle.loads(raw_pickle)
25+
except Exception as ex:
26+
sys.exit(1)
27+
28+
result_str = ''.join('\\x{:02x}'.format(ord(x)) for x in pickle_str)
29+
print(result_str)
30+
sys.exit(0)

src/gui/gui_factory.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#include <fastonosql/core/value.h>
3131

32+
#include "proxy/settings_manager.h"
33+
3234
#define CONNECT_GIF_PATH_RELATIVE "share/resources/help/connect.gif"
3335
#define INDIVIDUAL_BUILDS_GIF_PATH_RELATIVE "share/resources/help/individual_builds.gif"
3436
#define WORKFLOW_GIF_PATH_RELATIVE "share/resources/help/workflow.gif"
@@ -470,7 +472,7 @@ const QString& GuiFactory::pathToLoadingGif() const {
470472
}
471473

472474
QString GuiFactory::pathToIndividualBuilds() const {
473-
const std::string absolute_source_dir = common::file_system::absolute_path_from_relative(RELATIVE_SOURCE_DIR);
475+
const std::string absolute_source_dir = proxy::SettingsManager::GetSourceDirPath();
474476
const std::string img_full_path =
475477
common::file_system::make_path(absolute_source_dir, INDIVIDUAL_BUILDS_GIF_PATH_RELATIVE);
476478
QString path;
@@ -479,15 +481,15 @@ QString GuiFactory::pathToIndividualBuilds() const {
479481
}
480482

481483
QString GuiFactory::pathToConnectGif() const {
482-
const std::string absolute_source_dir = common::file_system::absolute_path_from_relative(RELATIVE_SOURCE_DIR);
484+
const std::string absolute_source_dir = proxy::SettingsManager::GetSourceDirPath();
483485
const std::string img_full_path = common::file_system::make_path(absolute_source_dir, CONNECT_GIF_PATH_RELATIVE);
484486
QString path;
485487
common::ConvertFromString(img_full_path, &path);
486488
return path;
487489
}
488490

489491
QString GuiFactory::pathToWorkflowGif() const {
490-
const std::string absolute_source_dir = common::file_system::absolute_path_from_relative(RELATIVE_SOURCE_DIR);
492+
const std::string absolute_source_dir = proxy::SettingsManager::GetSourceDirPath();
491493
const std::string img_full_path = common::file_system::make_path(absolute_source_dir, WORKFLOW_GIF_PATH_RELATIVE);
492494
QString path;
493495
common::ConvertFromString(img_full_path, &path);

src/proxy/settings_manager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <common/utils.h>
2828

2929
#include <common/file_system/file_system.h>
30+
#include <common/file_system/string_path_utils.h>
3031
#include <common/qt/gui/app_style.h>
3132
#include <common/qt/translations/translations.h>
3233

@@ -133,6 +134,10 @@ std::string SettingsManager::GetSettingsFilePath() {
133134
return common::file_system::prepare_path(kIniPath);
134135
}
135136

137+
std::string SettingsManager::GetSourceDirPath() {
138+
return common::file_system::absolute_path_from_relative(RELATIVE_SOURCE_DIR);
139+
}
140+
136141
uint32_t SettingsManager::GetConfigVersion() const {
137142
return config_version_;
138143
}

src/proxy/settings_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class SettingsManager : public common::patterns::Singleton<SettingsManager> {
4848

4949
static std::string GetSettingsDirPath();
5050
static std::string GetSettingsFilePath();
51+
static std::string GetSourceDirPath();
5152

5253
uint32_t GetConfigVersion() const;
5354

tests/pickle_string.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/redis_test_keys.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ def test():
167167
# {'type': 'big', 'url': '....'}])
168168
r.set('pickled_object', pickled_object)
169169

170+
pickled2_object = pickle.dumps('pickle2')
171+
r.set('pickled2_object', pickled2_object)
172+
170173
# double name
171174
space_key = 'hello motto'
172175
space_value = 'hello motto'

0 commit comments

Comments
 (0)