[ubuntu-uk] Python Question
Hello Everyone, I have scoured the web and can only find half baked answers to my question - I'm hoping someone here can help? I know that Python is classed as a portable programming language (it will run on anything) So I'm wondering how do you code in such a way that your script can just be 'ported' over to another OS? I have this code to locate the Firefox directory: from subprocess import Popen, PIPE li = Popen(['find', '/', '-iname', '*.default'], stdout=PIPE).stdout.read().split('\n') flag = 1 for item in li: if item.find('firefox') != -1: print outfile, Firefox Directory: , item flag = 0 break It works fine on my Ubuntu machine, It won't run on a Windows machine (haven't tested) I think because I'm calling the unix version of find and also my path is /, obviously this would be c: in windows. I want to search the entire disk of any OS to find the Firefox cache directory. Is it even possible to do this? I don't particularly need the code to do it (I don't mind if you want to share though!) What I'm really after is - Am I wasting my time even trying? Best Regards, Dave Hanson http://hansonforensics.co.uk -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Python Question
On 2011-09-23 15:38, Dave Hanson wrote: I want to search the entire disk of any OS to find the Firefox cache directory. Is it even possible to do this? I don't particularly need the code to do it (I don't mind if you want to share though!) What I'm really after is - Am I wasting my time even trying? The problem is that you're using tools external to python, which are platform-dependent. Consider instead using the os.path python library. Regards, Tyler -- In a time of universal deceit, telling the truth is a revolutionary act. -- George Orwell -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Python Question
On Fri, 2011-09-23 at 15:38 +0100, Dave Hanson wrote: [...] It works fine on my Ubuntu machine, It won't run on a Windows machine (haven't tested) I think because I'm calling the unix version of find and also my path is /, obviously this would be c: in windows. It won't work because you're using find. Your popen in running a command (find) and it's not available on Windows. I want to search the entire disk of any OS to find the Firefox cache directory. Is it even possible to do this? I don't particularly need the code to do it (I don't mind if you want to share though!) What I'm really after is - Am I wasting my time even trying? You can do it in a 100% pythonic way (not calling external commands), although I would use platform specific code for that instead of scanning the whole disk. ie. if sys.platform == 'win32': # run windows code elif sys.platform == 'darwing': # run mac code ... etc ... Then on windows import the required win32 crap to get firefox directory from the registry. On Linux you can guess that the directory will be on $HOME/.mozila/* and the like, so use a list of possible directories. Regards, Juanjo -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Python Question
On 23 September 2011 15:38, Dave Hanson d...@hansonforensics.co.uk wrote: Hello Everyone, I have scoured the web and can only find half baked answers to my question - I'm hoping someone here can help? I know that Python is classed as a portable programming language (it will run on anything) So I'm wondering how do you code in such a way that your script can just be 'ported' over to another OS? I have this code to locate the Firefox directory: from subprocess import Popen, PIPE li = Popen(['find', '/', '-iname', '*.default'], stdout=PIPE).stdout.read().split('\n') flag = 1 for item in li: if item.find('firefox') != -1: print outfile, Firefox Directory: , item flag = 0 break It works fine on my Ubuntu machine, It won't run on a Windows machine (haven't tested) I think because I'm calling the unix version of find and also my path is /, obviously this would be c: in windows. I want to search the entire disk of any OS to find the Firefox cache directory. Is it even possible to do this? I don't particularly need the code to do it (I don't mind if you want to share though!) What I'm really after is - Am I wasting my time even trying? Simple answer is that there probably isn't anything that's universal so it would be easier to detect the OS using sys.platform and write specific code for each platform. s/ -- Twitter: @sfgreenwood Is this your sanderling? -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Python Question
Thanks Tyler, I did look at that but saw no way to tell it to use the entire disk. Juanjo/Simon - Thanks, that was the only alternative I could think of but considered it long winded if there was a sort of universal option like Tyler suggested. I'll probably use sys.platform then. It's not much more coding to be fair, the docs show only 8 variations on the output for the different operating systems. I suppose I was more interested in seeing what's possible and trying to understand the language a bit better. Once I'm in the directory I am querying the SQLite files so that shouldn't be platform specific from then on I wouldn't have thought as I would use the sqlite3 python module? Thanks again for the fast responses. I should have just posted here instead of searching for two hours - Doh! Best Regards, Dave Hanson http://hansonforensics.co.uk On Fri, Sep 23, 2011 at 3:43 PM, Tyler J. Wagner ty...@tolaris.com wrote: On 2011-09-23 15:38, Dave Hanson wrote: I want to search the entire disk of any OS to find the Firefox cache directory. Is it even possible to do this? I don't particularly need the code to do it (I don't mind if you want to share though!) What I'm really after is - Am I wasting my time even trying? The problem is that you're using tools external to python, which are platform-dependent. Consider instead using the os.path python library. Regards, Tyler -- In a time of universal deceit, telling the truth is a revolutionary act. -- George Orwell -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Python Question
On 23 September 2011 09:56, Dave Hanson d...@hansonforensics.co.uk wrote: Thanks again for the fast responses. I should have just posted here instead of searching for two hours - Doh! Don't forget the guys at Python IRC [http://www.python.org/community/irc/]... they've been very helpful to me in the past! -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/