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

    Join Date
    Sep 2003
    Location
    OSLO
    Posts
    17
    Rep Power
    0

    Please help debug.


    Hello!

    Can anyone see any error in this piece of code? (It is not made by me, but I cannot get it to work. It yields

    ./install.py: line 5: syntax error near unexpected token `faile(c'
    ./install.py: line 5: `def faile(cmd):'

    when I utilize it.

    Below is the code.

    Thanks in advance,

    Ronny Mandal


    -- start --
    # !/usr/bin/env python

    import os,sys,shutil,re

    def faile(cmd):
    print '%s: Running %s failed' % (sys.argv[0],cmd)
    sys.exit(1)

    if os.name=='posix': # unix?
    origdir=os.getcwd()
    dir='install'
    #if not os.path.isdir(dir):
    # os.mkdir(dir)
    os.chdir(dir)

    print 'Generating makefile using qmake.........'
    cmd='qmake'
    failure=os.system(cmd)
    if failure: faile(cmd)

    print 'Attempting make...'
    cmd='make'
    failure=os.system(cmd)
    if failure: faile(cmd)

    print 'Cleaning objekt files....'
    cmd='rm *.o Makefile'
    failure=os.system(cmd)
    if failure: faile(cmd)

    cmd='mv MuseSveis ../'
    failure=os.system(cmd)
    if failure: faile(cmd)

    os.chdir(origdir)
    print 'Run by typing MuseSveis'
    else:
    print 'Use linux!!\n'

    -- end --
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    The first error is that the code has not been posted with [ CODE] tags, so the indentation is lost.

    I can't find the second error until the first is fixed.

    Dave - The Developers' Coach
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    OSLO
    Posts
    17
    Rep Power
    0
    Originally Posted by DevCoach
    The first error is that the code has not been posted with [ CODE] tags, so the indentation is lost.

    I can't find the second error until the first is fixed.

    Dave - The Developers' Coach

    --

    Sorry, here it is again.

    Regards,

    RM

    Code:
    # !/usr/bin/env python
    
    import os,sys,shutil,re
    
    def faile(cmd):
            print '%s: Running %s failed' # (sys.argv[0],cmd)
            sys.exit(1)
    
    if os.name=='posix':                # unix?
            origdir=os.getcwd()
            dir='install'
            #if not os.path.isdir(dir):
            #       os.mkdir(dir)
            os.chdir(dir)
    
            print 'Generating makefile using qmake.........'
            cmd='qmake'
            failure=os.system(cmd)
            if failure: faile(cmd)
    
            print 'Attempting make...'
            cmd='make'
            failure=os.system(cmd)
            if failure: faile(cmd)
    
            print 'Cleaning objekt files....'
            cmd='rm *.o Makefile'
            failure=os.system(cmd)
            if failure: faile(cmd)
    
            cmd='mv MuseSveis ../'
            failure=os.system(cmd)
            if failure: faile(cmd)
    
            os.chdir(origdir)
            print 'Run by typing MuseSveis'
    else:
            print 'Use linux!!\n'
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    First problem that comes to mind is that os.system() returns 0 if the command goes well - since to OS's 0 is true and none 0 is false, on the other hand, Python sees this a little differently. What this means to you?

    Is you need to change lines like this..

    Code:
    failure = os.system(cmd)
    if failure: faile(cmd)
    into something like..

    Code:
    success = os.system(cmd)
    if not success: faile(cmd)
    I may be wrong, but that makes a lot of sence to me . Then i am a little odd .

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You might also want to loose re, and shutil from your import statment since they are not being used anywhere in the program as of yet . This means that you have to waist time importing something your program never uses.

    Mark.
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    OSLO
    Posts
    17
    Rep Power
    0

    Thanks, but


    thanks alot, but I still get the error message 'error near unexpected token..." as recently.

    It seems like they've done a wrong declaration of the 'faile'. Or...

    Hmm..

    I appreciate all help.


    Cheers!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    That line looks ok, but is it possible that it is not using the regular ASCII character set? If it is has a character from the extended unicode char set in the line, then it may make Python choke. That is the only thing I can think of that would cause that error message.

    Try examining the original file in hex.

    Dave - The Developers' Coach

IMN logo majestic logo threadwatch logo seochat tools logo