Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-23222

Tool for importing existing Python projects, i.e. generating .pyproject files

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • None
    • Python Support
    • None
    • All

    Description

      It would be very nice to have functionality for importing an existing Python project into Qt Creator. I guess it is really about generating the .pyproject file. For now I'm using the following Python script to generate it, where I can specify which file types to include:

       

      import os
      
      #Which file types to add to the project file
      file_types = (".py", ".xml", ".dtd", ".sh")
      
      #Open a project file and write the needed start of the project file syntax
      projectFileName = "MyProject.pyproject"
      f = open(projectFileName, "w")
      f.write("{\n\t\"files\": [")
      
      #Walk recursively through the folder structure and write all files
      #with the given file types into the project file.
      nFiles = 0
      for dirpath, dirnames, files in os.walk('.'):
          for file_name in files:
              if (file_name.endswith(file_types)):
                  if (len(dirpath) == 1):
                      f.write("\"" + file_name + "\",") #Root folder
                  else:
                      f.write("\"" + dirpath[2:] + "/" + file_name + "\",") #Need relative path down in the folder tree
                  nFiles += 1
      
      #Remove trailing comma after the last file name
      f.seek(-1, os.SEEK_END)
      f.truncate()
      
      #Write ending syntax and close the project file
      f.write("]\n}")
      f.close()
      
      print "Created and added " + str(nFiles) + " files to the project file: " + projectFileName + "."
      

      Attachments

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            jonei Jon Eiesland
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: