Skip to content

setting up pycharm project for preimport script

craigmcchesney edited this page Mar 14, 2022 · 15 revisions
  • create a directory for the github repo e.g.,
    • mkdir /home/craig/cable-import
  • change to that directory
    • cd /home/craig/cable-import
  • for convenience, create a directory here for input/output/config files
    • mkdir /home/craig/cable-import/run
    • move your existing folders configDir, inputDir, and outputDir to this run folder, so you'll have directories:
      • /home/craig/cable-import/run/configDir (containing your existing ".conf" files"
      • /home/craig/cable-import/run/inputDir (containing your input workbook xlsx files)
      • /home/craig/cable-import/run/outputDir (directory where script output is generated)
    • edit preimport.conf to change inputDir and outputDir to these new directories:
      • [DEFAULT]
      • inputDir = /home/craig/cable-import/run/inputDir
      • outputDir = /home/craig/cable-import/run/outputDir
  • change back to directory /home/craig/cable-import and clone the github repo:
  • open pycharm, select "close project" from file menu to close existing project if any
  • on pycharm window, select "create new project"
    • in "New Project" dialog, click folder icon to right of "Location:" bar
    • in "Select Base Directory" dialog, navigate to directory "/home/craig/cable-import/ComponentDB/tools/developer_tools/utilities/cable_import", selecting "cable_import" and click "OK"
    • in "New Project" dialog, expand "Project Interpreter", select "Existing Interpreter", and select python 3.7
    • click "OK" to create project
    • accept dialog with message that directory is not empty, and to create project from existing sources
  • open pycharm project settings (on linux, this is "Settings" on File menu, but on Mac it is "Project Preferences" or something along those lines
    • expand "Project: cable_import" from left sidebar (in linux, maybe not necessary on mac)
    • select "Project Interpreter" node under project and make sure python 3.7 is displayed
    • select "Project Structure" node under project and add cdb python api
      • in right sidebar, click "Add Content Root"
      • navigate up two levels and back down to python-client (/home/craig/cable-import/ComponentDB/tools/developer_tools/python-client)
      • select "python-client" folder and click "OK"
    • click Apply/OK to close project settings
  • in the left pycharm sidebar, you should now have a "cable_import" item with children "cable_import" and "python_client", and another item "External Libraries"
  • run the script
    • expand "cable_import" top-level item in left sidebar, expand child "cable_import", and select script "preImport.py"
    • right click on "preImport.py" and select "Create preImport.py" with blue and yellow "+" shaped icon to its left to create a new "run configuration"
    • in "Name" enter something like "IT CableType - Kabelbox"
    • in "Parameters", enter "--configDir /home/craig/cable-import/run/configDir --groupId IT --deploymentName KABELBOX"
    • click "OK"
    • click the run button (green right-pointing arrow in toolbar)
  • script output should be displayed in "Run" console at bottom of pycharm window

updating project from git

To update the project when I make changes, you'll simply click the down-left pointing blue arrow in the pycharm toolbar. The first time you do that, you'll see a dialog. Click the first radio button (Merge the incoming....), and click "Don't show again". Click "OK". You'll see a message displayed in the lower right part of the pycharm window that file(s) were updated. You can click the "Version Control" tab on the bottom of the pycharm window (or click "View Commits" in the update message) to see the details of what was updated. In the future, clicking the blue arrow will not open the dialog, it will just update the files and display the update message in the lower right.

Clone this wiki locally