4

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. 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. For example when I execute this:

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. I assume then that I have to create this .udb file which is a db file.

I am trying to avoid using Understands GUI and automate this static tool within a python script. 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!

Community
  • 1
  • 1
jshaf
  • 309
  • 1
  • 18

1 Answers1

1

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.

@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
KETAN PATIL
  • 2,276
  • 2
  • 13
  • 18