forked from chen310/NeteaseCloudMusicTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
**/tempCodeRunnerFile.py | ||
**/__pycache__/ | ||
/.user_data/ | ||
**/test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,23 @@ | ||
import json | ||
import json5 | ||
import re | ||
import copy | ||
import sys | ||
sys.path.append("..") | ||
from utils import jsonDumps | ||
from utils import updateConfig | ||
|
||
key_list = ['version', 'desp'] | ||
|
||
|
||
def copy_config(src, dst): | ||
target = copy.deepcopy(dst) | ||
if isinstance(src, dict): | ||
for key in src: | ||
if key in target: | ||
if key not in key_list: | ||
target[key] = copy_config(src[key], target[key]) | ||
else: | ||
target[key] = src[key] | ||
elif isinstance(src, list): | ||
if len(src) == 0: | ||
target = src | ||
if len(src) > 0: | ||
if len(target) == 0: | ||
target = copy.deepcopy(src) | ||
else: | ||
if isinstance(src[0], dict): | ||
t = target[0] | ||
target = [] | ||
for item in src: | ||
target.append(copy_config(item, t)) | ||
else: | ||
target = copy.deepcopy(src) | ||
else: | ||
target = copy.deepcopy(src) | ||
return target | ||
def before(src, dst): | ||
key_list = ['version', 'desp'] | ||
for key in src: | ||
if key in dst: | ||
if key in key_list: | ||
src[key] = dst[key] | ||
|
||
|
||
config = json5.load(open(sys.argv[1], 'r', encoding='utf-8')) | ||
oldconfig = json5.load(open(sys.argv[2], 'r', encoding='utf-8')) | ||
|
||
data = copy_config(oldconfig, config) | ||
before(oldconfig, config) | ||
|
||
data = updateConfig(oldconfig, config) | ||
|
||
with open(sys.argv[1], 'w', encoding='utf-8') as f: | ||
f.write(json.dumps(data, indent=4, ensure_ascii=False)) | ||
f.write(jsonDumps(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import copy | ||
import json | ||
|
||
def updateConfig(src, dst): | ||
target = copy.deepcopy(dst) | ||
if isinstance(src, dict): | ||
for key in src: | ||
target[key] = updateConfig(src[key], target[key]) | ||
elif isinstance(src, list): | ||
if len(src) == 0: | ||
target = src | ||
else: | ||
if len(target) == 0: | ||
target = copy.deepcopy(src) | ||
else: | ||
if isinstance(src[0], dict): | ||
t = target[0] | ||
target = [] | ||
for item in src: | ||
target.append(updateConfig(item, t)) | ||
else: | ||
target = copy.deepcopy(src) | ||
else: | ||
target = copy.deepcopy(src) | ||
return target | ||
|
||
def jsonDumps(data): | ||
return json.dumps(data,indent=4,ensure_ascii=False) |