I have a program that calls a couple of DOS commands, moves files, ZIPS them, and FTPs them to a server. When I test it in IDLE, works fine. I have tried to make into a EXE using pyInstaller and py2exe, both EXEs make the the program die immediatelt. Tried debugging, everything, cannot figure it out.

# FTP v0.3
# Writen by Kevin Culinane

import ftplib
import os
import sys
import traceback
import datetime
import subprocess
import shutil
import zipfile
import time
#This section defines the variables

today = datetime.date.today()
yesterday = (today + datetime.timedelta(days=-1))
host='site.ftp.site'
port='**'
login='***
password='***'
some_directory='***'
fullname='C:\\crunchtime'


#This section renames the zip file with todays date

os.chdir('c:\\sc')
subprocess.Popen(['posidbfw', '/alt', '1', '1'])
subprocess.Popen(['tarw', '-r', '52', '1', '1', '/alt'])

time.sleep(10)

shutil.rmtree('c:\\crunchtime')
os.mkdir('c:\\crunchtime')

os.chdir('c:\\altdbf')

shutil.copy2('c:\\altdbf\\cashout.dbf', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\chkitems.dbf', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\deposits.dbf', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\DISCOUNT.DBF', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\hrsales.dbf', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\nrt.DBF', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\paidouts.DBF', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\salestax.DBF', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\shftsls.DBF', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\names.DBF', 'c:\\crunchtime')
shutil.copy2('c:\\altdbf\\payrpunc.DBF', 'c:\\crunchtime')


os.chdir('c:\\crunchtime')

allFileNames = os.listdir('c:\\crunchtime')

myZipFile = zipfile.ZipFile("CT" +yesterday.strftime('%m%d%y') + ".zip", 'w')

for fileName in allFileNames:
    (name, ext) = os.path.splitext( fileName )
    print "Writing..." + fileName
    myZipFile.write( fileName, os.path.basename(fileName), zipfile.ZIP_DEFLATED )

myZipFile.close()


#This section starts the FTP process

print "Files:", 'c:\\crunchtime\\CT' + yesterday.strftime('%m%d%y') + '.zip'

print "Logging in..."
ftp = ftplib.FTP()
ftp.connect(host, port)
print ftp.getwelcome()
try:
    try:
        ftp.login(login, password)
        ftp.cwd(some_directory)
        # move to the desired upload directory
        print "Currently in:", ftp.pwd()

        print "Uploading...",
        fullname = 'c:\\crunchtime\\CT' + yesterday.strftime("%m%d%y") + '.zip'
        name = os.path.split(fullname)[1]
        f = open(fullname, "rb")
        ftp.storbinary('STOR ' + name, f)
        f.close()
        print "OK"
        
        print "Files:"
        print ftp.retrlines('LIST')
    finally:
        print "Quitting..."
        ftp.quit()
except:
    traceback.print_exc()

login='***
should be
login='***'

It is, that just happened when I took out the real info and replaced with *

Try using this

if __name__ == '__main__':
     main()

That may help. I'm guessing you are familiar with it, and therefor i don't need to explain

Chris

Try using this

if __name__ == '__main__':
     main()

That may help. I'm guessing you are familiar with it, and therefor i don't need to explain

Chris

That is used to test a module. Why would that help here, there isn't even a main()????

Ofcourse he would have to create a main function containing all of his program.

Depending on how py2exe works it may be needed for the program to initialize correctly

Nope, still not working. I added a main function to it, and fixed my indentation errors, and again, tested great in IDLE, when I compile with pyInstaller, it still flashes briefly, and BLAM, dies on the vine. I am wondering with all those modules imported, it isn't copying them all? Or maybe a problem with the OS module because that is the first call? Just don't know.

I suggest a debugging technique: you comment out large parts of your program until it runs, then you uncomment more and more until you find the problem. You can use multiline strings to comment easily ;)

Found one issue, and it was with the subprocess it was importing, replaced, and we move forward. Now, I get an error when I try to run build.py. In mf.py, line 253, import hooks, no module named hooks. And this is very true. I have a folder named hooks, with a bunch of hook_*.py. I have ihooks.py in the Lib folder, no hooks. Any help, would be awesome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.