Log in

View Full Version : File Browser


Fuzzgtp
February 19th, 2010, 09:42 AM
Working on a multi-os filebrowser for Boxee, but I need some help as I have neither a Mac or a Linux box to test on.

Was wondering if i could get some help converting this to work on both of those OS's or if someone can just explain to me the basic setups of the OS and test it for me.

Once i get the basic python script I will create a GUI for it in Boxee and anyone can use it.

http://www.fuzzthed.com/python/filebrowser.py

Basically when you run this (on windows), it lists all available drives and you use
cd("c:") and cd("python") to navigate through directories.

StevenR
February 19th, 2010, 11:44 AM
On Mac OS X there are no drive letters like on Windows. Drives are mounted to mount points, which by default (at least for me in Snow Leopard) are located under /Volumes/

Below is a possible implementation of a Mac version of the find_drives function from your Python script based on this information:


def find_drives_mac():
L = []
path = "/Volumes/"
drvList=os.listdir(path)
for each in drvList:
if (os.path.isdir(path + each)):
L.append(path + each + "/")
return L


The other difference is that path components are separated by forward slashes instead of back slashes, like:
/Volumes/MyDrive/MyDir/MyFile.txt
I think Linux also uses forward slashes for paths.

A test of your Python script using the code above and replacing the back slashes with forward slashes seems to work.

agentlame
February 19th, 2010, 12:58 PM
Don't hard-code path separators.

I think it is:

os.sep


But, I could be wrong.

Fuzzgtp
February 19th, 2010, 01:18 PM
Don't hard-code path separators.

I think it is:

os.sep


But, I could be wrong.

that seems right. ty

Fuzzgtp
February 19th, 2010, 01:38 PM
the file has been updated to include those changes.

StevenR if you could run that code now and see if it works. Will crash on Linux now, as find_drives() won't be found.

Neil could you give me some insight as to what the root path should looks like?

StevenR
February 19th, 2010, 03:32 PM
The code to get the drives now works on the Mac. I noticed that you have missed one of the path separators in the GetFiles function. The line which reads

path = file[0] + "\\"

should read

path = file[0] + os.sep


With that change it can correctly retrieve the directories and files on the Mac - I tested this by replacing file = [] with file = [find_drives()[0]] to make it list the directories and files in the first drive it finds.

agentlame
February 19th, 2010, 03:58 PM
the file has been updated to include those changes.

StevenR if you could run that code now and see if it works. Will crash on Linux now, as find_drives() won't be found.

Neil could you give me some insight as to what the root path should looks like?

Yeah, hit me on IM, tonight. I'll take a closer look at the whole thing.

Sorry I forgot about it, before.

Fuzzgtp
February 19th, 2010, 04:08 PM
The code to get the drives now works on the Mac. I noticed that you have missed one of the path separators in the GetFiles function. The line which reads

path = file[0] + "\\"

should read

path = file[0] + os.sep


With that change it can correctly retrieve the directories and files on the Mac - I tested this by replacing file = [] with file = [find_drives()[0]] to make it list the directories and files in the first drive it finds.

Ok changed the missing os.sep.

So when you first run the script is showing the list of 'drives'?
you should be able to do cd("drive") and it should show the list of contents of that drive .
Is this working? Sorry if that's what you meant, but the way you had to modify code to test it worries me Oo

StevenR
February 19th, 2010, 04:50 PM
Calling cd("drive") where drive is the path of one of the drives works fine. I hadn't noticed about the cd function, and my test code was basically just a way of doing the same thing.

Fuzzgtp
February 19th, 2010, 04:50 PM
yeah the cd should let you navigate through folders. Like cd("c:") then cd("documents and settings") and then cd("..") takes you back a directory