鉴于以下计划:
#!/usr/bin/env python
import click
@click.command()
@click.argument("arg")
@click.option("--opt")
@click.option("--config_file", type=click.Path())
def main(arg, opt, config_file):
print("arg: {}".format(arg))
print("opt: {}".format(opt))
print("config_file: {}".format(config_file))
return
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
我可以使用命令行提供的参数和选项来运行它.
$ ./click_test.py my_arg --config_file my_config_file
arg: my_arg
opt: None
config_file: my_config_file
Run Code Online (Sandbox Code Playgroud)
如何提供一个配置文件(ini?yaml?py?json?)到--config_file并接受内容作为参数和期权的价值?
例如,我想要my_config_file包含
opt: my_opt
Run Code Online (Sandbox Code Playgroud)
并有程序的输出显示:
$ ./click_test.py my_arg --config_file my_config_file
arg: my_arg
opt: my_opt
config_file: my_config_file
Run Code Online (Sandbox Code Playgroud)
我找到了callback看起来很有用的函数,但我找不到修改同一函数的兄弟参数/选项的方法.
我有MainGerritServer很多项目.
另外,我RogueGerritServer也有很多项目.
我正在寻找一种方式来移动ProjectA从RogueGerritServer到MainGerritServer同时保留这两个混帐提交历史以及与格里特回顾历史.
例如,我想将Android项目的Gerrit历史记录导入到我自己的Gerrit服务器上,这样当我在Android的分叉版本上工作时,我可以在本地服务器上查找Gerrit历史记录.最好的方法是什么?
如果它是一个简单的Git安装,我只需克隆ProjectA到我的电脑然后推送到MainGerritServer.基于Gerrit的项目是否以相同的方式工作?
我担心因为Gerrit安装在后台使用数据库,我不确定是否还需要迁移数据库中的信息.我看到很多关于采用数据库转储并将其移动到全新服务器的线程.但是,我试图只移动一个项目,因此采用数据库转储似乎不合适.我看到的最接近的答案是,这仍然不是我正在寻找的.
我很感激任何帮助,特别是如果你能告诉我我是否误解了如何处理这个问题.
谢谢
我正在用Python编写一个简单的版本更新程序,正则表达式引擎给了我巨大的麻烦.
特别是,即使使用re.MULTILINE选项,^和$也无法正确匹配.字符串匹配没有^和$,但没有其他喜悦.
如果你能发现我做错了什么,我将非常感谢你的帮助.
谢谢
target.c
somethingsomethingsomething
NOTICE_TYPE revision[] = "A_X1_01.20.00";
somethingsomethingsomething
Run Code Online (Sandbox Code Playgroud)
versionUpdate.py
fileName = "target.c"
newVersion = "01.20.01"
find = '^(\s+NOTICE_TYPE revision\[\] = "A_X1_)\d\d+\.\d\d+\.\d\d+(";)$'
replace = "\\1" + newVersion + "\\2"
file = open(fileName, "r")
fileContent = file.read()
file.close()
find_regexp = re.compile(find, re.MULTILINE)
file = open(fileName, "w")
file.write( find_regexp.sub(replace, fileContent) )
file.close()
Run Code Online (Sandbox Code Playgroud)
更新:感谢John和Ethan的有效观点.但是,如果我保留$,正则表达式仍然不匹配.一旦我删除$,它就会再次起作用.