Python: on which disk(s) is my user share located?


Recommended Posts

For my sabnzbd post script (python) i want to determine if the disk where i'm going to move my downloaded bluray, episode etc to, has enough diskspace.

I know how to find out the free space on a disk, but what i dont know is how do i know on what disk my user share is located? E.g. the user share /mnt/user/TVSeries/Fringe is located in /mnt/disk2/TVSeries/Fringe ...

 

I am using split level 1, so a tvseries in this case will only be on one disk. But which one? ;D

(I want to keep level 1 splits, so changing split levels is not the way for me)

Link to comment

Sorry, the cache drive mover is not efficient en not suited. The stuff gets downloaded to the cache drive in the first place. It will then be moved to another location ON THE CACHE DRIVE by unraid... until the mover at night finally takes it away to the array. I've left that idea years ago. All it does is taking up space, and moving stuff around multiple times.

 

I DO have a cache drive, but is it purely used a an SSD, my apps run on it, and i use it to directly download to, so i dont have to spin up disks.

After stuff is downloaded, i move it to the array myself using the script i talked about before.

 

I just want to extend that script.

Link to comment

Sorry, the cache drive mover is not efficient en not suited. The stuff gets downloaded to the cache drive in the first place.

If you move it yourself directly on the Cache drive to the correct final folder that is almost instantaneous.

It will then be moved to another location ON THE CACHE DRIVE by unraid... until the mover at night finally takes it away to the array. I've left that idea years ago. All it does is taking up space, and moving stuff around multiple times.

This is only true if you move it to user share that is cache enabled.  It is not true if the user share is not cache enabled, or if you move it to the correct folder on the cache disk for mover to later pick it up.

 

I DO have a cache drive, but is it purely used a an SSD, my apps run on it, and i use it to directly download to, so i dont have to spin up disks.

After stuff is downloaded, i move it to the array myself using the script i talked about before.

 

I just want to extend that script.

If you are not using the cache drive as a cache drive then simply set the User Shares to say Use Cache: No and then moving the file will write directly to the array without you having to worry about which disk will be used.
Link to comment

Again, i do NOT want to use the cache drive & mover. It works fine if you want to copy stuff from outside the array on to the array, but not if you downloading internally on the SSD drive. If you do so, it will get moved AGAIN to the ssd, and it was allready there. Sorry, i appreciate the comments, but i am not looking for any answers in this direction. Even then, i want to control when i get a message the disk is full, not at night when the mover runs and i'm not watching. If the mover warns about full disks at all...

 

I also do NOT want to fill up the ssd drive with stuff that will get moved many hours later. I need the ssd space for my downloaded stuff, and when the download is complete, it has to be moved AWAY from the ssd to the array itself, freeing up the ssd immediatly. If i'm downloading a tv series containg of 4 or 5 or 6 bluray disks, i need the ssd space. My ssd is 128GB. A bluray is about 40GB. You understand?

 

i found some code to iterate through the attached volumes, so i think i can write my extensions now.

Link to comment

For those interested:

 

import os
import sys

def GetFreeSpace(disk):
    st = os.statvfs('/mnt/' + disk )
    free = st.f_bavail * st.f_frsize/1024/1024/1024 #GB
    return free
    
def FindDiskFor(seriename):
    from os import listdir
    for mnt in listdir('/mnt'):
        #find all mounted disks
        if('disk' in mnt):
            #get all rootfolders on this disk
            folders = listdir('/mnt/' + mnt )
            for folder in folders:
                #not all disks contain a TVSeries folder, if found, use it
                if('TVSeries' in folder):
                    #this is a TVSeries folder, get it's content
                    tvseries = listdir('/mnt/' + mnt + '/TVSeries')
                    for serie in tvseries:
                        #now find our tvserie
                        if(seriename in serie):
                            #return the disk on which we found it
                            return mnt

def GetSizeOf(folder):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(folder):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            total_size += os.path.getsize(fp)
    return total_size/1024/1024/1024 

# main()
if __name__ == "__main__":
    arg1 = sys.argv[1]
    disk = FindDiskFor(arg1)
    print "Found '" + arg1 + "' at " + '/mnt/' + disk + '/TVSeries/' + arg1

    size = GetSizeOf('/mnt/' + disk + '/TVSeries/' + arg1)
    print "Size of show is: ", size, "G" 

    freespace = GetFreeSpace(disk)
    print "Free space on /mnt/" + disk + ":" , freespace , "G" 

 

result:

root@UNRAID:/mnt/cache/Temp/sabnzbd scripts# python test1.py House
Found 'House' at /mnt/disk4/TVSeries/House
Size of show is:  1630 G
Free space on /mnt/disk4: 72 G

Link to comment
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.