perforce - p4python 创建并提交一个新文件
问题描述
如何使用 p4python 创建和提交新文件?
create_and_submit_file(full_path_in_depot, new_file_text_content):
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
p4 = get_p4() # implemented
try: # Catch exceptions with try/except
connect_and_login_p4(p4) # implemented
# .. implementation here .. p4.some_call()
LOGGER.info('done')
except P4Exception:
for e in p4.errors: # Display errors
LOGGER.error(e)
解决方案
如果该文件已经存在于工作空间内的本地文件系统中,那么您需要做的就是p4.run_add(file)
和p4.run_submit('-d', 'this is my awesome file')
.
如果文件不存在,您需要创建它,如果您没有工作区,您也需要创建它。为简洁起见,以下是您从命令行完全从头开始执行此操作的方法(这可以直接映射到 P4Python,但我对您的环境知之甚少,无法为您提供开箱即用的代码,所以我不会尝试翻译):
echo "my awesome file content" > my_awesome_file
p4 set P4CLIENT=my_awesome_client
p4 --field "View=//depot/... //my_awesome_client/..." client -o | p4 client -i
p4 add my_awesome_file
p4 submit -d "this is my awesome file"
查看示例p4.save_client
以查看如何使用 P4Python 创建/修改客户端规范并修改字段以适应您的环境的简单示例(类似于我如何使用--field
标志来设置View
根my_awesome_client
对应的//depot/...
):
https://www.perforce.com/perforce/r14.2/manuals/p4script/python.p4.html#python.p4.save_spectype
推荐阅读
- linux - 如何使命令“Hadoop”在 linux 18.04 中工作?
- angular - 如何定义 api 的 DTO 类并在 Angular 7 SSR 中使用它们
- django - TypeError:“NoneType”对象不可迭代 Django Filter Values_List
- blockchain - 在 oo7 Substrate UI 中,Alice 的资金为零
- javascript - 组件不使用 react-transition-group 进行动画处理,只是立即更新?
- dynamics-crm - Microsoft Dynamics 365 OData 服务不使用显示名称
- ios - Firebase - 读取和获取数据的效率
- python-3.x - 如何在 Python 中根据日期列绘制分类变量
- javascript - 使用 Javascript 隐藏同级框动画
- html - flex: n 具有不同的 n 个项目