/[cvs]/nfo/projects/netfraggle/bin/fraggleEngine.py
ViewVC logotype

Annotation of /nfo/projects/netfraggle/bin/fraggleEngine.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Wed Aug 25 22:47:28 2004 UTC (20 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.1: +51 -0 lines
File MIME type: text/x-python
some engine-methods (getSetting, setSetting); urlOpener-class

1 joko 1.2 #!/usr/bin/env python
2    
3 joko 1.1 import os
4 joko 1.2 from fraggleConstants import *
5 joko 1.1
6     class FraggleEngine:
7 joko 1.2 """Back-end doing the work."""
8     def __init__(self):
9     self.settings = {}
10 joko 1.1
11     def getDefaultDir(self):
12     """Gets location of default dir and creates it
13     if necessary. ($HOME/.pears/)"""
14     try:
15     import pearsdebug
16     savedir = pearsdebug.savedir
17     except:
18     dir = '.netfraggle'
19     savedir = os.path.expanduser(os.path.join('~', dir))
20     if len(savedir)<=len("c:\\/" + dir):
21     # problem that might occur on Win2k (no $HOME environment variable)
22     temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir)
23     if temp > len("c:\\/" + dir):
24     savedir = temp
25     # create dir if it doesn't exist
26     if not os.path.exists(savedir):
27     os.makedirs(savedir)
28     return savedir
29 joko 1.2
30     def setSetting(self, settingname, value):
31     """Sets settingname to value in self.settings."""
32     self.settings[settingname] = value
33    
34     def getSetting(self, settingname, default=None):
35     """Returns settingname from self.settings. If not found
36     and default!=None, the default value is return *and*
37     saved to the settings."""
38     if self.settings.has_key(settingname):
39     return self.settings[settingname]
40     else:
41     if default!=None:
42     self.setSetting(settingname, default)
43     return default
44     else:
45     return None
46    
47    
48     class urlOpener(object):
49     """Opens urls."""
50     def __init__(self):
51     pass
52     def open(self, url="", command=None):
53     """Opens the url with the method defined in the settings.
54     If command==None, it is retreived from the settings.
55     """
56     if command==None:
57     command = FraggleEngine().getSetting(BROWSERCOMMAND, BROWSERDEFAULT)
58     if command==BROWSERDEFAULT.strip():
59     # use default opening method
60     import os
61     if os.environ.has_key("BROWSER") and \
62     os.environ["BROWSER"]=='kfmclient openProfile webbrowsing':
63     print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"]
64     os.environ["BROWSER"] = 'konqueror' # set it to konqueror
65     import webbrowser # MUST be imported only AFTER os.environ has been modified
66     webbrowser.open(url, 1)
67     #webbrowser.open_new(url)
68     else: #otherwise use user-defined command line
69     # replase %URL with actual url
70     command = command.replace("%URL", url)
71     import os
72     os.system(command)
73    

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed