#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Lightbulb From Python Script, execute python file with argument conditions


    I'm new to python and after reading materials on libraries sys, getopt, and argparse I'm even more confused.
    I'm trying to make a python script to execute calcdeps.py with what I'd call CLI arguments so that a more accurate merge of javascript files can happen (with Google Code's compiler.jar)
    So.. here's what I have so far and of course, I'm missing some important pieces somewhere:
    Code:
    #1 /user/bin/env python
    # Made in Eclipse with PyDev for Python 2.7+ -XRMod
    import sys
    import getopt
    import argparse
    #Edit the path variables to match your particular setup.
    CALCDEPS_PATH = 'C:/Compiler/ClosureLibrary/closure/bin/' #directory containing calcdeps.py
    DEPS_PATH = 'C:/Compiler/ClosureLibrary/closure/goog/' #directory containing deps.py
    JAR_PATH = 'C:/Compiler/ClosureLibrary/' #directory containing compiler.jar
    CLOSURE_PATH = 'C:/Compiler/ClosureLibrary/' #contains directory "closure"
    SCRIPT_PATH = 'C:/Compiler/ClosureLibrary/' #directory containing your scripts
    #Calcdeps will now be executed with arguments using PATH variables
    execfile('CALCDEPS_PATH/calcdeps.py',)
    --input DEPS_PATH/deps.js \
    --input SCRIPT_PATH/Firefly.js \
    --input SCRIPT_PATH/hover.js \
    --output_mode compiled \
    --compiler_jar JAR_PATH/compiler.jar \
    --compiler_flags "--compilation_level=ADVANCED_OPTIMIZATIONS" \
    --compiler_flags "--warning_level=VERBOSE" \
    --compiler_flags "--define=goog.LOCALE='de'" > output-compiled.js
    So how do I go about properly defining the arguments and executing the file with them?
    I'm in a windows 7 x64 environment using Eclipse with PyDev.
    Thank you for help.

    Edit:
    I forgot to mention, I'm using Python 2.7
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Guessing what you might need:
    Code:
    #! /user/bin/env python
    # Made in emacs by Lambert Electronics, LLC.  USA, NY.
    
    # mmmmm, why do you need to do this in python?
    import os
    
    os.environ['CALCDEPS_PATH'] = 'C:/Compiler/ClosureLibrary/closure/bin/'
    os.environ['DEPS_PATH'] = 'C:/Compiler/ClosureLibrary/closure/goog/'
    os.environ['JAR_PATH'] = 'C:/Compiler/ClosureLibrary/'
    os.environ['CLOSURE_PATH'] = 'C:/Compiler/ClosureLibrary/'
    os.environ['SCRIPT_PATH'] = 'C:/Compiler/ClosureLibrary/'
    
    os.popen('''python CALCDEPS_PATH/calcdeps.py --input DEPS_PATH/deps.js --input SCRIPT_PATH/Firefly.js --input SCRIPT_PATH/hover.js --output_mode compiled --compiler_jar JAR_PATH/compiler.jar --compiler_flags "--compilation_level=ADVANCED_OPTIMIZATIONS" --compiler_flags "--warning_level=VERBOSE" --compiler_flags "--define=goog.LOCALE='de'" > output-compiled.js''')
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    # mmmmm, why do you need to do this in python?
    Because it won't work in .bat as arguments as I couldn't get arguments passed to python script from command prompt.

    And every google doc script I found didn't work for me when ran.
    Thank you very much. I appreciate this deeply. Although I now have a different error in that somewhere along the arguments one of the scripts did not like as only empty JS are produced. I'll have to figure out what's not kosher here.

IMN logo majestic logo threadwatch logo seochat tools logo