import os
from smb.SMBConnection import SMBConnection
from smb.smb_structs import OperationFailure
def deletefile(file):
try:
os.remove(file)
print("%s删除成功!" % file)
except PermissionError:
deletefile(file=file)
if __name__ == '__main__':
connect = SMBConnection(username='mytian', password='mytian'
, domain='mytian', remote_name='mytian', my_name='gang.zhou')
connect.connect(ip='10.0.1.11')
f = os.listdir('.')
uploadOkFiles = []
for item in f:
if item.endswith(".apk"):
splites = item.split('-')
channelName = ''
packageName = ''
if -1 != splites[0].find('Rz'):
packageName = 'Rz'
channelName = splites[0].replace('Rz', '')
if -1 != splites[0].find('Ma'):
packageName = 'Ma'
channelName = splites[0].replace('Ma', '')
if -1 != splites[0].find('En'):
packageName = 'En'
channelName = splites[0].replace('En', '')
if -1 != splites[0].find('Lo'):
packageName = 'Lo'
channelName = splites[0].replace('Lo', '')
if -1 != splites[0].find('Ph'):
packageName = 'Ph'
channelName = splites[0].replace('Ph', '')
if -1 != splites[0].find('Pb'):
packageName = 'Pb'
channelName = splites[0].replace('Pb', '')
if -1 != splites[0].find('Xz'):
packageName = 'Xz'
channelName = splites[0].replace('Xz', '')
if -1 != splites[0].find('St'):
packageName = 'St'
channelName = splites[0].replace('St', '')
if -1 != splites[0].find('So'):
packageName = 'So'
channelName = splites[0].replace('So', '')
if -1 != splites[0].find('Bk'):
packageName = 'Bk'
channelName = splites[0].replace('Bk', '')
if -1 != splites[0].find('Py'):
packageName = 'Py'
channelName = splites[0].replace('Py', '')
if -1 != splites[0].find('MaV'):
packageName = 'MaV'
channelName = splites[0].replace('MaV', '')
if -1 != splites[0].find('LoV'):
packageName = 'LoV'
channelName = splites[0].replace('LoV', '')
if -1 != splites[0].find('RzV'):
packageName = 'RzV'
channelName = splites[0].replace('RzV', '')
if -1 != splites[0].find('EnV'):
packageName = 'EnV'
channelName = splites[0].replace('EnV', '')
if -1 != splites[0].find('PyV'):
packageName = 'PyV'
channelName = splites[0].replace('PyV', '')
if -1 != splites[0].find('Gx'):
packageName = 'Gx'
channelName = splites[0].replace('Gx', '')
if -1 != splites[0].find('Ls'):
packageName = 'Ls'
channelName = splites[0].replace('Ls', '')
typeP = 'Debug'
if -1 != item.find('release'):
typeP = 'Release'
try:
connect.createDirectory(service_name='version_release'
, path='/NewMGarden/%s' % packageName)
except OperationFailure:
pass
try:
connect.createDirectory(service_name='version_release'
, path='/NewMGarden/%s/%s' % (packageName, channelName))
except OperationFailure:
pass
try:
connect.createDirectory(service_name='version_release'
, path='/NewMGarden/%s/%s/%s' % (packageName, channelName, typeP))
except OperationFailure:
pass
try:
connect.createDirectory(service_name='version_release'
, path='/NewMGarden/%s/%s/%s/%s' % (packageName, channelName, typeP
, 'V%s' % splites[splites.__len__() - 2]))
except OperationFailure:
pass
try:
connect.storeFile(service_name="version_release"
, path='/NewMGarden/%s/%s/%s/%s/%s' % (packageName, channelName, typeP
, 'V%s' % splites[splites.__len__() - 2], item)
, file_obj=open(file=item, mode='rb'))
print("%s上传成功!" % item)
uploadOkFiles.append(item)
except OperationFailure:
pass
connect.close()
for item in uploadOkFiles:
deletefile(item)
网友评论