leoxv.py :  » Network » Rufus-BitTorrent-Client » Rufus_0.7.0_src » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Rufus BitTorrent Client 
Rufus BitTorrent Client » Rufus_0.7.0_src » leoxv.py
#! /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 + ' &')

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.