0

I am new to python trying to make a code that will give me infromation in csv file of c drive freespace and existance of software path.

below is the code I am trying..

import time
import csv
import os
import socket
import ctypes
import platform
import sys

timestr = time.strftime("%Y.%m.%d")

filepath = r"D:\_library\_abcd\test"
filename = timestr + ".csv"

machinename = socket.gethostname()
print machinename

def Get_free_space_mb(direname):
    if platform.system() == 'Windows':
        free_bytes = ctypes.c_ulonglong(0)
        ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(direname),None, None, ctypes.pointer(free_bytes))
        print(free_bytes.value / 1024 / 1024 )
        return free_bytes.value / 1024 / 1024
    else:
        st = os.statvfs(dirname)
        return st.f_bavail * st.f_frsize / 1024 / 1024

Cdrivespace = Get_free_space_mb("C:\\")

def software1():
    if os.path.isdir("C:\Program Files\software1"):
        return "software1 Exist"
    else:
        return "software1 not Exist"
software_1 = software1()

def software2():
    if os.path.isdir("C:\Program Files\software2"):
        return "software2 Exist"
    else:
        return "Nuke9 not Exist"
software_2 = software2()

def software3():
    if os.path.isdir("C:\Program Files\software3"):
        return "software3 Exist"
    else:
        return "software3 not Exist"
software_3 = software3()

with open(os.path.join(filepath,filename), 'ab+') as file_:
writer = csv.writer(file_,delimiter=",")
data = [machinename,Cdrivespace,software1,software2,software3]
writer.writerows([data])

The output I am getting in csv is : (SUPT5) (10150) (function software1 at 0x02AF47B0) (function software2 at 0x02AF4A70) (function software3 at 0x02AF4AB0)

what is expected output is : (SUPT5) (10150MB) (software1 exist) (software2 exist) (software3 not exist)

also I want to csv file to write mb after writing value of Cdrivespace. anything changes which I can make to code more easy ?

1
  • suggestion - instead of writing 3 separate functions sw1, sw2, sw3, combine into one and pass arguments Commented Oct 6, 2017 at 5:18

1 Answer 1

1

Try this in your data line:

data = [machinename, str(Cdrivespace) + 'MB', software_1, software_2, software_3]

You were referencing the software1 etc. functions, not the returned values (software_1 etc).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.