简体   繁体   English

有没有办法在python脚本中创建一个理解(来自Scitools)数据库?

[英]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.

相关问题 如何执行 Scitools 理解来自 python 的命令 - How to execute Scitools Understand commands from python 如何使用Python和SciTools Understand API为类计算CBO和LCOM - How to calculate CBO and LCOM for a class using Python and SciTools Understand API 有什么方法可以为python3脚本创建应用程序吗? - Is there any way to create an app for python3 script? 无法导入scitools python - unable to import scitools python 检查 MySQL 数据库是否从 Python 中更改的最快方法? - Fastest way to check if MySQL db changed from within Python? 导入理解(来自sciTools)给出ImportError:DLL加载失败:%1不是有效的Win32应用程序 - import understand (from sciTools) gives ImportError: DLL load failed: %1 is not a valid Win32 application 有什么方法可以通过在wagtail中执行python脚本来创建和发布页面? - Is there any way to create and publish pages by executing python script in wagtail? 检测命令是否修改了 Python 脚本中目录中的任何文件 - Detect if a command modifies any files from a directory within a Python script python中是否有任何方法或任何框架可以从xml创建对象模型? - Is there any way or any framework in python to create an object model from a xml? 我的cmd有没有办法从Python中打印出任何unicode? - Is there a way for my cmd to print out any unicode from within Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM