Skip to content

Commit 376e02a

Browse files
committed
添加图床配置修改子命令
1 parent 9abde32 commit 376e02a

File tree

5 files changed

+76
-11
lines changed

5 files changed

+76
-11
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pip install --upgrade markdown-img-icexmoon
5656

5757
1. 执行`python -m markdown_img -h`
5858

59-
### 查看版本信息
59+
### 查看版本及配置信息
6060

6161
执行`pymdimg -v``pymdimg --version`
6262

@@ -105,7 +105,9 @@ pip install --upgrade markdown-img-icexmoon
105105

106106
1. 执行`python -m markdown_img -c smms`
107107

108-
> 具体参数可以查看帮助文档。
108+
> - 具体参数可以查看帮助文档。
109+
>
110+
> - 部分图床配置如果是多项,可以使用子命令仅修改其中单一配置,比如仅修改腾讯云的存储目录:`pymdimg -c qcloud --des_dir image`,如果目标目录中间有空格,需要给将其用英文双引号包起来,比如这样:`pymdimg -c qcloud --des_dir "我 love 你"`。更新完配置后可以使用`pymdimg -v`确认配置是否已经设置正确。
109111
110112
### 扫描图片并创建索引
111113

@@ -201,4 +203,10 @@ python -m markdown_img -m refresh
201203

202204
### 0.2.4
203205

204-
添加了腾讯云对象存储作为图床。
206+
添加了腾讯云对象存储作为图床。
207+
208+
### 0.2.5
209+
210+
- 添加了修改腾讯云图床的子命令。
211+
- 修改查看版本命令,增加程序相关配置信息的显示。
212+
- 修改帮助文档。

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = markdown-img-icexmoon
3-
version = 0.2.4
3+
version = 0.2.5
44
author = icexmoon
55
author_email = [email protected]
66
description = A program for find and upload images in markdown file and will replace them.

src/markdown_img/__main__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
from .main import Main
55

66

7+
def getOptionVal(options, key):
8+
for optKey, optVal in options:
9+
if optKey == key:
10+
return optVal
11+
return None
12+
13+
714
def main():
815
try:
916
opts, args = getopt.gnu_getopt(sys.argv[1:], 'm:hvi:c:s', [
10-
'mode=', 'help', 'version', 'img_service=', 'change_token=', 'scan'])
17+
'mode=', 'help', 'version', 'img_service=', 'change_token=', 'scan', 'des_dir='])
1118
except getopt.GetoptError as e:
1219
print("获取参数信息出错,错误提示:", e.msg)
1320
exit()
@@ -21,10 +28,7 @@ def main():
2128
if argKey == '--help' or argKey == '-h':
2229
mainProcess.outputHelpInfo()
2330
elif argKey == '--version' or argKey == '-v':
24-
import pkg_resources
25-
version = pkg_resources.get_distribution(
26-
'markdown-img-icexmoon').version
27-
print("version:{}".format(version))
31+
mainProcess.printSysInfo()
2832
elif argKey == '--mode' or argKey == '-m':
2933
mode = argVal
3034
if mode == 'img_recove':
@@ -38,7 +42,12 @@ def main():
3842
elif argKey == '--img_service' or argKey == '-i':
3943
mainProcess.changeImgService(argVal)
4044
elif argKey == '--change_token' or argKey == '-c':
41-
mainProcess.changeToken(argVal)
45+
optDesDirVal = getOptionVal(opts, '--des_dir')
46+
if argVal == 'qcloud' and optDesDirVal is not None:
47+
mainProcess.changeImgServiceOption(
48+
argVal, {'des_dir': optDesDirVal})
49+
else:
50+
mainProcess.changeToken(argVal)
4251
elif argKey == '--scan' or argKey == '-s':
4352
mainProcess.scanAndCreateIndex()
4453
else:

src/markdown_img/help.info

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
rruu 如优图床。
1212
vimcn Vim-CN图床,访问速度偏慢。
1313
yujian 遇见图床。
14-
qcloud 腾讯云对象存储(需要提供必要连接信息,如果不知道如何获取,请阅读https://cloud.tencent.com/document/product/436/7751#.E6.9C.AF.E8.AF.AD.E4.BF.A1.E6.81.AF
14+
qcloud 腾讯云对象存储(需要提供必要连接信息)
1515
-c --change_token 替换图床访问令牌
1616
rruu 如优图床。
1717
smms sm.ms图床。
1818
yujian 遇见图床。
1919
qcloud 腾讯云对象存储
20+
支持子选项
21+
--des_dir 仅更新腾讯云oss上的存储目录
2022
-s --scan 扫描当前目录的图片并生成网络图床索引

src/markdown_img/main.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,49 @@ def scanAndCreateIndex(self):
321321
print("!["+imgName+"]("+webImgUrl+")\n", file=fopen)
322322
print("已成功生成网络图床索引文件:markdown_img_index.md")
323323
return True
324+
325+
def changeImgServiceOption(self, imgServiceFlag, options):
326+
'''修改图床服务的部分配置'''
327+
sysConfig = Config()
328+
if imgServiceFlag == Config.IMG_SERVICE_QCLOUD:
329+
try:
330+
qCloudInfo = sysConfig.getQCloudInfo()
331+
except UserException as e:
332+
self.dealUserException(e)
333+
if Config.QCLOUD_INFO_DES_DIR in options and options[Config.QCLOUD_INFO_DES_DIR]:
334+
qCloudInfo[Config.QCLOUD_INFO_DES_DIR] = options[Config.QCLOUD_INFO_DES_DIR]
335+
sysConfig.setConfigParam(Config.PARAM_QCLOUD_INFO, qCloudInfo)
336+
sysConfig.writeMainConfig()
337+
print('图床配置已更新')
338+
339+
def printSysInfo(self):
340+
'''打印当前系统相关信息'''
341+
sysConfig = Config()
342+
import pkg_resources
343+
version = pkg_resources.get_distribution(
344+
'markdown-img-icexmoon').version
345+
print("软件版本:{}".format(version))
346+
try:
347+
imgService = sysConfig.getConfigParam(Config.PARAM_IMG_SERVICE)
348+
print("当前使用的图床:{}".format(imgService))
349+
print("图床的相关配置信息:")
350+
if imgService!= Config.IMG_SERVICE_QCLOUD:
351+
if imgService == Config.IMG_SERVICE_ALI or imgService == Config.IMG_SERVICE_YUJIAN:
352+
token = sysConfig.getYujianToken()
353+
elif imgService == Config.IMG_SERVICE_ALI2 or imgService == Config.IMG_SERVICE_RRUU:
354+
token = sysConfig.getRruuToken()
355+
elif imgService == Config.IMG_SERVICE_SMMS:
356+
token = sysConfig.getSmmsToken()
357+
else:
358+
token = ''
359+
print("\t访问令牌:{}".format(token))
360+
else:
361+
#显示腾讯云相关配置信息
362+
qcloudInfo = sysConfig.getQCloudInfo()
363+
print("\t存储桶:{}".format(qcloudInfo[Config.QCLOUD_INFO_BUCKET]))
364+
print("\tsecret_id:{}".format(qcloudInfo[Config.QCLOUD_INFO_SECRET_ID]))
365+
print("\tsecret_key:{}".format(qcloudInfo[Config.QCLOUD_INFO_SECRET_KEY]))
366+
print("\t地域:{}".format(qcloudInfo[Config.QCLOUD_INFO_REGION]))
367+
print("\t存储目录:{}".format(qcloudInfo[Config.QCLOUD_INFO_DES_DIR]))
368+
except UserException as e:
369+
self.dealUserException(e)

0 commit comments

Comments
 (0)