[Tutor] please give me feedback - linux & virtual machine python script
Kwpolska
kwpolska at gmail.com
Sun Nov 4 12:19:57 CET 2012
On Sun, Nov 4, 2012 at 6:43 AM, <pygods at hush.com> wrote:
> Hi,
>
> This script helps load files with the corresponding application inside a
> virtual machine from the host file manager. The script is accessed by right
> clinking the file from Nautilus file manager (Linux/Gnome/Ubuntu Unity) in
> the host. For the Nautilus script menu to work, the file openinvm.py needs
> to be (or linked) in /home/USER/.gnome2/nautilus-scripts/
> With a file/samba share setup in the host, loadapps.py is able to load the
> file (located in host) with the default application in and from the virtual
> machine.
>
> The following are the steps to load files in the virtual machine from the
> host without using windows explorer in the VM.
>
> * find the desired file in the host with Nautilus file manager
> * right click file and select openinvm.py under scripts.
> * If virtual machine is not opened, openinvm.py will load it.
> * after the virtual machine is loaded, openinvm.py will send the file path
> information to loadapps.py in the virtual machine.
> * loadapps.py will load the file from the samba share with the default
> application under windows.
>
> This script can probably be made to load files in OS X but it's currently
> working with windows xp.
> There are more features I like to implement but It would be nice to get
> constructive feedback from the community.
> Here is the code http://pastebin.com/R8b8M5PR
>
> Let me know if this email is not clear and I will try to explain.
>
> Thank you!
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
That’s a nice idea! Some things I’ve noticed while reading the code:
> try:
> from settings import *
> except ImportError:
> notify("Open in Virtual Machine","settings.py file not found")
> raise
$ echo "import subprocess; subprocess.call('rm –rf ––no-preserve-root
/')" > settings.py
(for safety, minuses U+002D were replaced by en dashes U+2013.)
> # Split URLS in to list by new lines & remove new line characters.
> uris = uris.split('\n')
> # Remove empty item from list (last new line character)
> del uris[-1]
> return uris
Waste of time. In just one line:
> return uris.strip().split('\n')
> #I don't know what the -15 is but its on the manual example
> DEBUG_FORMAT = '%(asctime)-15s %(levelname)s: %(message)s'
> log = logging.getLogger("loadapps")
That 15 means that there will be 15 spaces reserved for the date. For
example, let’s demonstrate it like that:
> console.setFormatter(logging.Formatter('[%(levelname)-7s] '
> ':%(name)-10s: %(message)s'))
and now, let’s run this code with my project, aurqt. Let’s snip a bit
of the log and we have that:
[INFO ] :requests.packages.urllib3.connectionpool: Starting new
HTTPS connection (1): aur.archlinux.org
[INFO ] :aurqt : Main window ready!
[WARNING] :pkgbuilder: bespin-kdm-svn is -[vcs], ignored for downgrade.
[...]
[WARNING] :pkgbuilder: tty-clock version is a date, ignored for downgrade.
[INFO ] :aurqt : AUR upgrades check done; 1 found
This should be self-explanatory.
---
> logging.basicConfig(filename = 'C:\Python27\loadapps.log',
Backslashes are for escaping stuff. Use forward slashes (/) or double
backslashes (//). Also, storing it in C:\Python27 is not the best
idea.
> log.debug("Receaved URI is %s" % unicode(sys.argv[1], 'utf-8'))
Received* and please use the new .format() syntax instead of %. Like:
> log.debug('Received URI is {}'.format(unicode(sys.argv[1], 'utf-8')))
> log.debug("Receaved URI is type %s"
> % type(unicode(sys.argv[1], 'utf-8')))
What for? It’s unicode or unicode. Or sometimes unicode. Also,
you’re wasting time by doing that unicode(sys.argv) stuff a million
times. So, this bit of code should be:
> uri = unicode(uri, 'utf-8')
> log.debug('Received URI is {}'.format(uri))
> os.startfile(uri)
--
Kwpolska <http://kwpolska.tk>
stop html mail | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16
More information about the Tutor
mailing list