#! /usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Purpose: startfile and webbrowser linux support
#
# Author: Jukka Lehtomaki
# jukka.lehtomaki@gmail.com leoxv@users.sourceforge.net
# Created: 2004/30/11
# Copyright: (c) 2004 LeoXV.LICENSE.TXT
#-----------------------------------------------------------------------------
def startfile(url): ## By Jukka Lehtomaki
import sys, os
import urllib
import os
if sys.platform == 'linux2':
pathname = os.path.dirname(sys.argv[0])
browser = os.environ.get('FILEBROWSER')
file = 1
if browser == '':
browser = os.environ.get('BROWSER')
file = 2
flag = ''
browserfile = '0'
## flag = '--silent'
## flag = '-contentLocale'
## flag = '--no-default-window'
if browser == 'konqueror':
flag = ''
elif browser == 'nautilus':
flag = ''
elif browser == 'firefox':
flag = ''
elif browser == 'mozilla':
flag = ''
elif browser == 'xfe':
flag = ''
elif browser == 'rox':
flag = ''
browserfile = '1'
elif browser == 'dillo':
flag = ''
browserfile = '1'
print url
if os.path.exists(os.path.abspath(pathname) + '/' + url + '/'):
print url
url2 = parseurl(url, browserfile=browserfile, root='1')
if file == 1:
os.system('$FILEBROWSER' + ' ' + flag + ' "' + (os.path.abspath(pathname) + '/' + url2 + '/" &'))
elif file == 2:
os.system('$BROWSER' + ' ' + flag + ' "' + (os.path.abspath(pathname) + '/' + url2 + '/" &'))
elif os.path.exists(url + '/'):
url2 = parseurl(url, browserfile=browserfile)
if file == 1:
os.system('$FILEBROWSER' + ' ' + flag + ' ' + url2 + '/ &' )
elif file == 2:
os.system('$BROWSER' + ' ' + flag + ' ' + url2 + '/ &' )
else:
print "Folder not found."
def open_new(url): ## By Jukka Lehtomaki
import sys, os
print url
url = parseweburl(url)
if sys.platform == 'linux2':
os.system('$BROWSER' + ' ' + url + ' &' )
def parseurl(url, browserfile=0, root=0): ## By Jukka Lehtomaki
import string
url = url.lstrip('')
url = url.rstrip('')
url = string.replace(url, ' ', '\ ')
if root == 0:
if browserfile == 0:
url = '"' + url + '"'
url = 'file:' + url
print url
if 'rm' in url and 'rf' in url or 'fr' in url:
url = "Disabled for security reason"
if 'rm' in url and 'vrf' in url or 'fvr' in url or 'frv' in url:
url = "Disabled for security reason"
if 'rm' in url and '--force' in url or '--recursive' in url or '--directory' in url:
url = "Disabled for security reason"
return url
def parseweburl(url): ## By Jukka Lehtomaki
import string
url = url.lstrip('')
url = url.rstrip('')
print url
return url
def parseloadurl(url): ## By Jukka Lehtomaki
from urllib2 import URLError,urlopen
from urlparse import urlparse
import urllib
try:
quote0 = urllib.quote(urlparse(url)[0])
quote1 = urllib.quote(urlparse(url)[1])
quote2 = urllib.quote(urlparse(url)[2])
quote3 = urllib.quote(urlparse(url)[3])
quote4 = urllib.quote(urlparse(url)[4])
quote5 = urllib.quote(urlparse(url)[5])
h = urlopen(quote0 + '://' + quote1 + quote2 + quote3 + quote4 + quote5)
except:
h = url
print h
return h
def unparseloadurl(url): ## By Jukka Lehtomaki
from urllib2 import URLError,urlopen
from urlparse import urlparse
import urllib
from os.path import split,join
from socket import gaierror
try:
h = urllib.unquote(url)
except:
h = url
print h
return h
def echo_browser_test(): ## By Jukka Lehtomaki
import sys, os
print "Web Browser"
web = os.environ.get('BROWSER')
if web == None:
print "Software package rely on your $BROWSER variable being set."
print "export BROWSER='firefox'"
else:
print web
print "File Browser"
file = os.environ.get('FILEBROWSER')
if file == None:
print "Software package rely on your $FILEBROWSER variable being set."
print "export FILEBROWSER='konqueror'"
else:
print file
print "If you have filenames encoded in the encoding of your locale, then"
print "you may want to set the G_BROKEN_FILENAMES=1 environment variable."
def onclose(run): ## By Jukka Lehtomaki
import sys, os
print run
## if sys.platform == 'linux2':
## os.system(run + ' &')
def onstart(run): ## By Jukka Lehtomaki
import sys, os
print run
## if sys.platform == 'linux2':
## os.system(run + ' &')
|