Ich bin sehr neu in Python. Ich habe den folgenden Code, der eine Klasse mit drei Methoden hat Problem ist bei winCMD = 'NET USE '+ host + ' /User:' + self.user + ' ' + self.password
Zeile es beschwert sich immer für self.user
und self.password
als Objekt kann nicht in int konvertieren. Irgendwelche Ideen, was ich falsch mache?Kann Objekt implizit nicht in Python konvertieren
import subprocess
#from shutil import copyfile
import shutil
import os
class user_credentials:
def __init__(self, user, password):
self.user=user
self.password=password
def remoteCopyFile(host, self, source, destination):
winCMD = 'NET USE '+ host + ' /User:' + self.user + ' ' + self.password
subprocess.call(winCMD, shell=True)
getFileName=os.path.basename(source)
tempDestination=r"{0}\{1}".format(destination, getFileName)
try:
if not os.path.exists(tempDestination):
shutil.copy(source, destination)
print("Copied the Installer File Successfully")
else:
print("File alreade exists. Delete and recreate")
except:
e=sys.exc_info()[0]
print("Something went wrong: %s "%e)
def remoteCopyFolder(host, self, source, destination):
winCMD = 'NET USE '+ host + ' /User:' + self.user + ' ' + self.password
subprocess.call(winCMD, shell=True)
getDirectoryName=os.path.basename(source)
newDestination=r"{0}\{1}".format(destination, getDirectoryName)
try:
if not os.path.exists(newDestination):
print("copying files please wait....")
shutil.copytree(source, newDestination)
print("Copied the entire directory successfully")
else:
print("That folder already exists. Delete and recreate again")
except:
e=sys.exc_info()[0]
print("Something went wrong: %s "%e)
def createFolderOnNetwork(host, self, destination, folderName):
winCMD = 'NET USE '+ host + ' /User:' + self.user + ' ' + self.password
subprocess.call(winCMD, shell=True)
newPath=r"{0}\{1}".format(destination, folderName)
if not os.path.exists(newPath):
os.makedirs(newPath)
print("Created a folder successfully with name "+folderName)
else:
print("The folder already exists. Delete it and recreate")
oUser = user_credentials(r'Admin',r'ThePassword')
host = "10.90.100.193"
oUser.remoteCopyFile(host,r"\\vm-tfs\Builds\Athena_2.0\Athena_2.0_20160715.6\AltusDataAccessors.dll",r"\\10.90.100.193\Altus_Latest_Build\Binaries\BuildGen_Test")
oUser.remoteCopyFolder(host,r"\\vm-tfs\Builds\Athena_2.0\Athena_2.0_20160715.6",r"\\10.90.100.193\Altus_Latest_Build\Binaries\BuildGen_Test")
oUser.createFolderOnNetwork(host,r"\\10.90.100.193\Altus_Latest_Build\Binaries\BuildGen_Test","Test")
Dank Jim es funktioniert :) – nikhil