Community
    • Login

    Implementing project management/Opening copy files

    Scheduled Pinned Locked Moved General Discussion
    5 Posts 2 Posters 330 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Anthony BlincoA
      Anthony Blinco
      last edited by Anthony Blinco

      I am trying to implement a project management system (As simple for the user as possible)
      It works like this;
      I have a PROJECT.BAT file in my folder with my source files (Or in the parent folder)
      This PROJECT.BAT file is executed before I compile or run my my current source file so the user can specify any environment variables for the compiler or runtime by modifying PROJECT.BAT.
      Compile and running is accomplished by executing a cbl_function.bat file.
      I use NppExec to issue the command line $(SYS.COBOL)\cbl_function.bat COMPILE $(CURRENT_DIRECTORY) $(NAME_PART) $(EXT_PART)
      So the first parameter is COMPILE or RUN depending on what the user wants, then the PATH, NAME and EXTENSION parameters.
      cbl_function.bat will then run PROJECT.BAT (If it exists) and use any predefined variables that are set in PROJECT.BAT

      So this works fine.

      My issue is this;
      I have a python script that will parse a COBOL COPY filename statement and open the copy file
      So the pyhon script will need to extract the COPYPATH from the PROJECT.BAT file in order to find the COPY file
      This COPYPATH may contain references to other variables (%VARIABLE%)

      I am concerned that this will take too long. How can i parse the project file (when the source file is opened) and some how set a GLOBAL COPYPATH variable in python that will be available to my python script that opens my COPY files.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Anthony Blinco
        last edited by

        @Anthony-Blinco said in Implementing project management/Opening copy files:

        I have a python script that will parse

        I am assuming this to mean “I am using the PythonScript plugin to run a python script”. I make this clarification because using the PythonScript plugin to run a script has different implications as to the environment compared to calling an external python interpreter from the NppExec script. (I feel justified in this interpretation because later you say “parse the project file (when the source file is opened)”, which I infer to mean that the “python script” has access to a file that’s opened in Notepad++, which says to me that you’re using PythonScript plugin.)

        I am concerned that this will take too long. How can i parse the project file (when the source file is opened) and some how set a GLOBAL COPYPATH variable in python that will be available to my python script that opens my COPY files.

        I think this might not be the best way to go about it. Since the variables would not be set in the environment of the Notepad++ (which was run before the batch file, so maintains the original, unmodified environment), the values of the %Variables% wouldn’t be available to the python script , so you would basically have to write a batch-file interpreter in Python to get it to figure out the right value for each %Variable% before piecing together the final COPYPATH.

        As an alternative, I might suggest that you add a line at the end of the cbl_function.bat (or after running cbl_function.bat from the NppExec script) that will output a quick config-output file which just contains the value of COPYPATH. Maybe something like

        REM main contents , ending with:
        CALL PROJECT.BAT
        REM new code to put the final value of COPYPATH into a known file location
        echo %COPYPATH% > ./COPYPATH.out
        

        Then you could just have your python code read ./COPYPATH.out and use the text from that file to “set a GLOBAL COPYPATH variable in python”

        1 Reply Last reply Reply Quote 0
        • Anthony BlincoA
          Anthony Blinco
          last edited by

          Awesome

          1. Yes i am running notepad++ python script
          2. How do i set a global variable in notepad++ python script?
          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Anthony Blinco
            last edited by

            @Anthony-Blinco said in Implementing project management/Opening copy files:

            How do i set a global variable in notepad++ python script?

            The same way you do in normal python.

            The PythonScript environment has one instance for the whole run of Notepad++, so if you set the global variable in your script, it will stay set, and if you change the value, it will change. There is a trick you can use to make sure that it gets an initial value, and stays global all the time:

            global myGlobal
            try:
                myGlobal
            except NameError:
                myGlobal = "initial value"
            

            (That’s if you’re worried that you’re going to try to read a value from myGlobal before you set it)

            However, really, I cannot see a need for something that fancy, In your script, you should just be able to do

            def read_copypath_file:
                ...  # function to read the contents of the COPYPATH.out file
            
            COPYPATH = read_copypath_file()
            ... # remainder of your python script, where you want to be able to use the COPYPATH value
            

            And after that, COPYPATH will have the value that was read from the file.

            1 Reply Last reply Reply Quote 1
            • Anthony BlincoA
              Anthony Blinco
              last edited by

              Ok. Thanks very much for your help. I thought i might have to parse the .bat file to get an expanded variable but think i am going to go with your suggestion and make a script that runs when the source file is loaded that executes the project.bat and saves of the variables i need.
              That was a very good suggestion indeed. Thanks!

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors