Maison > Questions et réponses > le corps du texte
# -*- coding: utf-8 -*-
__author__ = 'kinfinger'
import os
import tkFileDialog
import tkMessageBox
import Pmw
import sys,Tkinter
import logging
from ftplib import FTP
sys.modules['tkinter']=Tkinter
from Tkinter import *
logging.basicConfig(level=logging.INFO)
class FileGuiChose(object):
def __init__(self,initdir=None,frame=None,showframe=None,bottomFrame=None):
self.entryvar =StringVar()
self.showframe=showframe
self.menuList=('/www/export/oms','/www/export/wms','/www/import/oms','/www/import/wms','/www/oversea/oms','/www/oversea/wms')
# top area
self.ftpMenuChines=[u'出口OMS',u'出口WMS',u'进口OMS',u'进口WMS',u'海外仓OMS',u'海外仓WMS']
self.glabel=Label(frame,text=u'本地项目根目录')
self.gentry=Entry(frame,textvariable=self.entryvar)
self.gbutton=Button(frame,command=self.opendir,text=u'选取目录')
self.keyListBox = Listbox(frame)
# initiatate the dropdown-list
self.keyvar=StringVar()
self.keyvar.set(u'请选择项目')
self.ftpdir=''
self.dropDownlist = Pmw.OptionMenu(frame,
labelpos='w',
label_text = u'选择200项目目录:',
menubutton_textvariable = self.keyvar,
items = self.ftpMenuChines,
menubutton_width = 15,
command=self.setFtpdir,
)
self.gentry.bind('<Return>',func=self.refresh)
self.glabel.grid(row=0,column=0,sticky=W)
self.gentry.grid(row=0,column=1)
self.gbutton.grid(row =0,column=2)
self.dropDownlist.grid(row=0,column=4,sticky=E)
# content area
self.textbar=Scrollbar(self.showframe,orient=VERTICAL)
self.textbar.pack(side=RIGHT,fill=Y)
# bottome area
self.bottomBar = Scrollbar(showframe,orient = HORIZONTAL,bg='black')
self.bottomBar.pack(side=BOTTOM,fill=X)
self.textbox=Text(self.showframe,yscrollcommand=self.textbar.set,xscrollcommand=self.bottomBar.set,wrap=CHAR)
self.textbox.pack(side=LEFT,fill=BOTH)
self.textbar.config(command=self.textbox.yview) # yview
self.bottomBar.config(command=self.textbox.xview) # xview
self.submitButton=Button(bottomFrame,text=u'上传文件',command=self.submit)
self.submitButton.grid(row=0,column=1)
#文本录入框的粘贴复制
self.copyMenu = Menu(self.showframe, tearoff=0)
self.copyMenu.add_command(label="复制", command=self.onCopy)
self.copyMenu.add_separator()
self.copyMenu.add_command(label="粘贴", command=self.onPaste)
self.copyMenu.add_separator()
self.copyMenu.add_command(label="剪切", command=self.onCut)
self.textbox.bind("<Button-3>", self.popupmenu)
self.dirname=''
def popupmenu(self,event):
self.copyMenu.post(event.x_root, event.y_root)
def onPaste(self):
try:
self.text = self.showframe.clipboard_get()
except TclError:
pass
self.textbox.insert(INSERT,str(self.text))
self.textbox.update()
def onCopy(self):
text = self.textbox.get(SEL_FIRST, SEL_LAST)
self.showframe.clipboard_clear()
self.showframe.clipboard_append(text)
def onCut(self):
text = self.textbox.get(SEL_FIRST, SEL_LAST)
self.textbox.delete(SEL_FIRST, SEL_LAST)
self.showframe.clipboard_clear()
self.showframe.clipboard_append(text)
def opendir(self):
#self.textbox.delete('1.0','9999999.0')
self.dirname=tkFileDialog.askdirectory()
self.entryvar.set(self.dirname) # related to entry just for show
showmessage=u'请选择本地文件目录'
if not self.dirname:
self.messageBox=tkMessageBox.showinfo(self.showframe,message=showmessage)
else:
self.dirname=self.entryvar.get()
#self.dirlist=os.listdir(self.entryvar.get())
#for eachdir in self.dirlist:
# self.textbox.insert(END,eachdir+'\r\n')
#self.textbox.update()
def refresh(self,event=None):
self.textbox.delete('1.0','9999999.0')
self.dirlist=os.listdir(self.entryvar.get())
for eachdir in self.dirlist:
self.textbox.insert(END,unicode(eachdir,'cp936')+'\r\n')
self.textbox.update()
def setFtpdir(self,event=None):
mulu=self.dropDownlist.getcurselection()
#key=-1
self.ftpdir=''
for key,value in enumerate(self.ftpMenuChines):
#key+=1
#logging.info(key)
if mulu==value:
self.ftpdir=self.menuList[key]
#tkMessageBox.showinfo(self.showframe,message=self.ftpdir)
break
return False;
#上传ftp
def submit(self,event=None):
result=''
#i=ctx.request.input(fileroot='',uplodaFile='',xiangmu='')
#logging.warning(i.uplodaFile.split('\n'));
#fileRootList=i.fileroot.split('\\')
#logging.warning(fileRootList)
if not self.dirname:
tkMessageBox.showinfo(self.showframe,message=u'请选择本地目录')
return False
if not self.ftpdir:
tkMessageBox.showinfo(self.showframe,message=u'请选择项目目录')
return False
userSystemDir=os.listdir(self.dirname)
#logging.warning(userSystemDir)
prefixPath=[]
movePath=[]
if not userSystemDir:
tkMessageBox.showinfo(self.showframe,message=u'请选择项目目录')
return False
uploadFileText=self.textbox.get('1.0','9999999.0')
if not uploadFileText:
tkMessageBox.showinfo(self.showframe,message=u'请输入上传的文件列表')
return False
#if not i.xiangmu:
#raise APIError(u'请选择项目目录')
#ftpDir=('/www/export/oms','/www/export/wms','/www/import/oms','/www/import/wms','/www/oversea/oms','/www/oversea/wms')
#ftpRoot=ftpDir[int(i.xiangmu)-1]
ftpRoot=self.ftpdir
localRoot=self.dirname.replace('\\','/')
ftp=FTP()
ftp.set_debuglevel(1)
ftp.connect('192.168.25.9')
ftp.login('apache','123456')
#ftp.cwd(ftpRoot)
#print ftp.pwd()
#print ftp.pwd()
#logging.warning(i.uplodaFile.split('\r\n'))
print uploadFileText
#os._exit(0)
for file in uploadFileText.split('\n'):
if not file:
continue
#logging.warning(userSystemDir)
#file=file.replace('/','\\')
fileAblute,replceNumber=re.subn(r'\\+','/',file)
preFix=getprefixPath(fileAblute,userSystemDir)
#logging.warning(preFix)
#os._exit(0)
#logging.warning(file)
if(preFix==False):
tkMessageBox.showinfo(self.showframe,message=file+u'目录不存在')
if(preFix):
localPath=fileAblute.replace('/'.join(preFix),localRoot).strip('\r\n').strip('\n')
#logging.warning(localPath)
#logging.warning(i.fileroot)
#logging.warning('/'.join(preFix))
#logging.warning(file)
#os._exit(0)
aimsFtpPath=fileAblute.replace('/'.join(preFix),ftpRoot).strip('\r\n').strip('\n')
else:
localPath=localRoot+fileAblute
localPath=localPath.strip('\r\n')
#aimsFtpPath=ftpRoot+'/'+fileAblute
aimsFtpPath='%s/%s'%(ftpRoot,fileAblute)
aimsFtpPath,number=re.subn(r'\\+|/+','/',aimsFtpPath)
aimsFtpPath=aimsFtpPath.strip('\r\n').strip('\n')
#logging.warning(ftpRoot)
#logging.warning(fileAblute)
logging.warning(aimsFtpPath)
#os._exit(0)
putStatus=putFile(aimsFtpPath,localPath,ftpRoot,ftp)
if putStatus==True:
movePath.append(aimsFtpPath)
ftp.quit()
#logging.warning(movePath)
successFile='\r\n'.join(movePath)
tkMessageBox.showinfo(self.showframe,message=successFile)
def putFile(aimsFtpPath,localDir,remoteDir,ftp):
#ftp.cwd('/www/export/wms/application/models/Common')
#ftp.storbinary("STOR "+os.path.basename('F:\\import_wms\\felix\\application\\models\\Common\\Status.php'),open('F:\\import_wms\\felix\\application\\models\\Common\\Status.php','rb'))
#os._exit(0)
#logging.warning(aimsFtpPath)
#os._exit(0)
if not remoteDir:
return False
#ftp.cwd(remoteDir)
aimtuple=os.path.split(aimsFtpPath)
logging.warning(aimtuple)
if not aimtuple or not aimtuple[0] or aimtuple[1]=='':
return False
#logging.warning(aimtuple)
aimDirList=aimtuple[0]
src=''
#logging.warning(u'循环3')
for file in aimDirList.split("/"):
src=src+'/'+file
#logging.warning(src)
try:
ftp.cwd(src)
except:
try:
ftp.mkd(src)
except:
raise APIError(u'ftp目录创建失败'+src)
ftp.cwd(src)
#logging.warning(localDir.replace('/','*'))
#testLocalDir='F:/chukouOms/application/models/Service/LogisticsProcess.php'
#print localDir[59]
#print localDir[60]
#print len(testLocalDir)
#logging.warning(os.path.isfile('F:/import_wms/felix/application/models/Table/CeiveUse.php'))
#ogging.warning(os.path.isfile(localDir))
if os.path.isfile(localDir):
ftp.storbinary("STOR "+os.path.basename(localDir),open(localDir,'rb'))
#logging.warning(open(localDir,'rb'))
#os._exit(0)
return True
#ftp.cwd('..')
return False
def getprefixPath(uploadFile,userSystemDir):
fileList=uploadFile.replace('\\','/').split('/')
preFix=[]
#logging.warning(fileList)
for filetemp in fileList:
#if not filetemp:
#preFix.append('/')
#continue
#logging.warning(filetemp)
if filetemp in userSystemDir:
return preFix
preFix.append(filetemp)
return False
class GuiMenu():
def hello(self):
pass
def File(self):
pass
def Edit(self):
pass
def View(self):
pass
def Help(self):
pass
def __init__(self,rootmenu):
self.root=rootmenu
self.menubar=Menu(rootmenu)
# create a pulldown menu, and add it to the menu bar
filemenu = Menu(self.menubar, tearoff=0)
filemenu.add_command(label="Open", command=self.File)
filemenu.add_command(label="New", command=self.File)
filemenu.add_command(label="Save", command=self.File)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=rootmenu.quit)
self.menubar.add_cascade(label="File", menu=filemenu)
# create more pulldown menus
editmenu = Menu(self.menubar, tearoff=0)
editmenu.add_command(label="Cut", command=self.Edit)
editmenu.add_command(label="Copy", command=self.Edit)
editmenu.add_command(label="Paste", command=self.Edit)
self.menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(self.menubar,tearoff=0)
helpmenu.add_command(label="About", command=self.Help)
self.menubar.add_cascade(label="Help", menu=helpmenu)
rootmenu.config(menu=self.menubar)
def main():
basePath=os.path.dirname(os.path.abspath(__file__))
root = Tk()
root.title(u'200FTP上传')
root.iconbitmap('%s/ooopic_1464314435.ico' % basePath)
root.columnconfigure(0,minsize=50)
topFrame=Frame(root,height=80)
contentFrame=Frame(root,bg='white')
bottomFrame=Frame(root,bg='green')
topFrame.pack(side=TOP)
contentFrame.pack(side=TOP)
bottomFrame.pack(side=TOP)
GuiMenu(root)
fguiChose=FileGuiChose(os.curdir,topFrame,contentFrame,bottomFrame)
mainloop()
if __name__ == '__main__':
main()
代码如上,一个文件,一个图标 python 2.7 版面,一个 Pmw-2.0.0 的模块,其他都是自带的
谁能帮忙弄下给个解决办法,我试了打包成 exe 总是执行不了
大家讲道理2017-04-17 17:59:34
Il est recommandé d'utiliser cxfreeze et de réessayer.
http://wenku.baidu.com/link?url=ERMhbPWhTr9BFFz8bEF1jRmAWvr26GvMVJIusM-SrKTcR_kf_Hmc55268stowIQqqDtux5ipV-v6CqwsD7oOyGM1KjxHf3Gi3gerdmR4yeq
高洛峰2017-04-17 17:59:34
Es-tu sous Windows ou Linux ?
Vous pouvez d'abord vérifier si le programme peut être exécuté
puis le conditionner, vous assurer que le conditionnement est réussi, puis exécuter le fichier exe
L'exe généré sous Windows ne peut pas être exécuté sous Linux, et l'exe généré sous Linux ne peut pas être exécuté sous Windows