[英]Is there any way to create an Understand (from Scitools) DB within a python script?
I am in the process of writing a python script to determine projects that reference a given project and have come across Understand from Scitools. 我正在编写一个python脚本来确定引用给定项目的项目,并且已经从Scitools中了解了解。 After research on the Understands Python API it appears that I need to “open” a DB in order to execute any commands and discover all there is to discover about a given project. 在研究了理解Python API之后,似乎我需要“打开”数据库以执行任何命令并发现所有关于给定项目的发现。 For example when I execute this: 例如,当我执行此操作时:
example.py example.py import understand import sys def sortedEntities(db): for ent in sorted(db.ents(),key= lambda ent: ent.name()): print (ent.name()," [",ent.kindname(),"]",sep="",end="\\n") if __name__ == '__main__': # Open Database args = sys.argv db = understand.open(args[1]) sortedEntities(db)
I am faced with an understand.UnderstandError: DBCorrupt error because I am not feeding in a .udb file and instead feeding in a .csproj file. 我面临一个理解.UnderstandError:DBCorrupt错误,因为我没有输入.udb文件,而是输入.csproj文件。 I assume then that I have to create this .udb file which is a db file. 我假设我必须创建这个.udb文件,这是一个db文件。
I am trying to avoid using Understands GUI and automate this static tool within a python script. 我试图避免使用理解GUI并在python脚本中自动化这个静态工具。 Is there any way I can create a DB from a given project and then execute the many commands Understand has to offer. 有没有什么办法可以从给定项目创建数据库,然后执行理解必须提供的许多命令。 Any guidance would be very much appreciated! 任何指导将非常感谢!
you can use the command line utility for this, udb_path
is where UDB is created, language
is Java/Python/c#/or whatever, project_root
is the root path of your project you want to run understand on. 你可以使用命令行实用程序, udb_path
是创建UDB的地方, language
是Java / Python / c#/或者其他什么, project_root
是你想要运行的项目的根路径。
@staticmethod
def create_udb(udb_path, language, project_root):
try:
output = subprocess.check_output(
"und create -db {udb_path} -languages {lang}".format(udb_path=udb_path, lang=language),
shell=True)
logging.info(output)
output = subprocess.check_output("und add -db {udb_path} {project}".format(
udb_path=udb_path, project=project_root), shell=True)
logging.info(output)
except subprocess.CalledProcessError as e:
logging.exception(e.output)
logging.fatal("udb creation failed")
raise Exception
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.