mirror of
https://github.com/siyuan-note/plugin-sample-vite-svelte.git
synced 2025-08-02 17:00:23 +00:00
更新 py 脚本的用法
This commit is contained in:
parent
ba8e431dec
commit
d8287067d2
1 changed files with 20 additions and 7 deletions
|
@ -1,12 +1,25 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
from argparse import ArgumentParser
|
|
||||||
|
# check path, must be in root folder
|
||||||
|
if not os.path.exists('plugin.json'):
|
||||||
|
os.chdir('..')
|
||||||
|
if not os.path.exists('plugin.json'):
|
||||||
|
print('plugin.json not found, exit')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# 1. Read plugin_dir
|
# 1. Read plugin_dir
|
||||||
parser = ArgumentParser()
|
plugin_dir = ''
|
||||||
parser.add_argument('plugin_dir')
|
if len(sys.argv) > 1:
|
||||||
args = parser.parse_args()
|
plugin_dir = sys.argv[1]
|
||||||
plugin_dir = args.plugin_dir
|
while not os.path.exists(plugin_dir):
|
||||||
|
plugin_dir = input('Please input the directory of siyuan/data/plugins: ')
|
||||||
|
if plugin_dir == 'exit' or plugin_dir == 'quit' or plugin_dir == 'q':
|
||||||
|
sys.exit()
|
||||||
|
if not os.path.exists(plugin_dir):
|
||||||
|
print('plugin_dir not found!')
|
||||||
|
continue
|
||||||
|
|
||||||
# 2. Read name in plugin.json
|
# 2. Read name in plugin.json
|
||||||
with open('plugin.json', 'r', encoding='utf-8') as f:
|
with open('plugin.json', 'r', encoding='utf-8') as f:
|
||||||
|
@ -16,7 +29,7 @@ name = content.get('name')
|
||||||
# ...error if name not found
|
# ...error if name not found
|
||||||
if not name or name == '':
|
if not name or name == '':
|
||||||
print('"name" in plugin.json not found, exit')
|
print('"name" in plugin.json not found, exit')
|
||||||
exit()
|
sys.exit()
|
||||||
|
|
||||||
dev_dir = os.path.abspath('dev')
|
dev_dir = os.path.abspath('dev')
|
||||||
if not os.path.exists(dev_dir):
|
if not os.path.exists(dev_dir):
|
||||||
|
@ -29,4 +42,4 @@ if not os.path.exists(os.path.join(plugin_dir, name)):
|
||||||
print('Symlink created:', link)
|
print('Symlink created:', link)
|
||||||
else:
|
else:
|
||||||
print('Folder already exists, exit')
|
print('Folder already exists, exit')
|
||||||
exit()
|
sys.exit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue