mirror of
https://github.com/gryf/wicd.git
synced 2026-02-21 17:35:46 +01:00
Merge in global script support.
This commit is contained in:
@@ -26,6 +26,10 @@ curses_revision = '%CURSES_REVNO%'
|
|||||||
lib = '%LIB%'
|
lib = '%LIB%'
|
||||||
share = '%SHARE%'
|
share = '%SHARE%'
|
||||||
etc = '%ETC%'
|
etc = '%ETC%'
|
||||||
|
scripts = '%SCRIPTS%'
|
||||||
|
disconnectscripts = '%SCRIPTS%disconnect'
|
||||||
|
preconnectscripts = '%SCRIPTS%preconnect'
|
||||||
|
postconnectscripts = '%SCRIPTS%postconnect'
|
||||||
images = '%IMAGES%'
|
images = '%IMAGES%'
|
||||||
encryption = '%ENCRYPTION%'
|
encryption = '%ENCRYPTION%'
|
||||||
bin = '%BIN%'
|
bin = '%BIN%'
|
||||||
|
|||||||
128
setup.py
128
setup.py
@@ -42,6 +42,7 @@ except Exception, e:
|
|||||||
print 'failed to find revision number:'
|
print 'failed to find revision number:'
|
||||||
print e
|
print e
|
||||||
|
|
||||||
|
|
||||||
class configure(Command):
|
class configure(Command):
|
||||||
description = "configure the paths that Wicd will be installed to"
|
description = "configure the paths that Wicd will be installed to"
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ class configure(Command):
|
|||||||
('lib=', None, 'set the lib directory'),
|
('lib=', None, 'set the lib directory'),
|
||||||
('share=', None, 'set the share directory'),
|
('share=', None, 'set the share directory'),
|
||||||
('etc=', None, 'set the etc directory'),
|
('etc=', None, 'set the etc directory'),
|
||||||
|
('scripts=', None, 'set the global scripts directory'),
|
||||||
('images=', None, 'set the image directory'),
|
('images=', None, 'set the image directory'),
|
||||||
('encryption=', None, 'set the encryption template directory'),
|
('encryption=', None, 'set the encryption template directory'),
|
||||||
('bin=', None, 'set the bin directory'),
|
('bin=', None, 'set the bin directory'),
|
||||||
@@ -91,11 +93,11 @@ class configure(Command):
|
|||||||
('no-install-ncurses', None, 'do not install the ncurses client')
|
('no-install-ncurses', None, 'do not install the ncurses client')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
self.lib = '/usr/lib/wicd/'
|
self.lib = '/usr/lib/wicd/'
|
||||||
self.share = '/usr/share/wicd/'
|
self.share = '/usr/share/wicd/'
|
||||||
self.etc = '/etc/wicd/'
|
self.etc = '/etc/wicd/'
|
||||||
|
self.scripts = self.etc + "scripts/"
|
||||||
self.icons = '/usr/share/icons/hicolor/'
|
self.icons = '/usr/share/icons/hicolor/'
|
||||||
self.images = '/usr/share/pixmaps/wicd/'
|
self.images = '/usr/share/pixmaps/wicd/'
|
||||||
self.encryption = self.etc + 'encryption/templates/'
|
self.encryption = self.etc + 'encryption/templates/'
|
||||||
@@ -175,10 +177,12 @@ class configure(Command):
|
|||||||
# If we don't get anything from *-config, or it didn't run properly,
|
# If we don't get anything from *-config, or it didn't run properly,
|
||||||
# or the path is not a proper absolute path, raise an error
|
# or the path is not a proper absolute path, raise an error
|
||||||
try:
|
try:
|
||||||
pmtemp = subprocess.Popen(["pkg-config","--variable=pm_sleephooks","pm-utils"], stdout=subprocess.PIPE)
|
pmtemp = subprocess.Popen(["pkg-config", "--variable=pm_sleephooks",
|
||||||
|
"pm-utils"], stdout=subprocess.PIPE)
|
||||||
returncode = pmtemp.wait() # let it finish, and get the exit code
|
returncode = pmtemp.wait() # let it finish, and get the exit code
|
||||||
pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout
|
pmutils_candidate = pmtemp.stdout.readline().strip() # read stdout
|
||||||
if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate):
|
if len(pmutils_candidate) == 0 or returncode != 0 or \
|
||||||
|
not os.path.isabs(pmutils_candidate):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
else:
|
else:
|
||||||
self.pmutils = pmutils_candidate
|
self.pmutils = pmutils_candidate
|
||||||
@@ -189,7 +193,8 @@ class configure(Command):
|
|||||||
kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE)
|
kdetemp = subprocess.Popen(["kde-config","--prefix"], stdout=subprocess.PIPE)
|
||||||
returncode = kdetemp.wait() # let it finish, and get the exit code
|
returncode = kdetemp.wait() # let it finish, and get the exit code
|
||||||
kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout
|
kdedir_candidate = kdetemp.stdout.readline().strip() # read stdout
|
||||||
if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate):
|
if len(kdedir_candidate) == 0 or returncode != 0 or \
|
||||||
|
not os.path.isabs(kdedir_candidate):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
else:
|
else:
|
||||||
self.kdedir = kdedir_candidate + '/share/autostart'
|
self.kdedir = kdedir_candidate + '/share/autostart'
|
||||||
@@ -199,10 +204,11 @@ class configure(Command):
|
|||||||
kde4temp = subprocess.Popen(["kde4-config","--prefix"], stdout=subprocess.PIPE)
|
kde4temp = subprocess.Popen(["kde4-config","--prefix"], stdout=subprocess.PIPE)
|
||||||
returncode = kde4temp.wait() # let it finish, and get the exit code
|
returncode = kde4temp.wait() # let it finish, and get the exit code
|
||||||
kde4dir_candidate = kde4temp.stdout.readline().strip() # read stdout
|
kde4dir_candidate = kde4temp.stdout.readline().strip() # read stdout
|
||||||
if len(kde4dir_candidate) == 0 or returncode != 0 or not os.path.isabs(kde4dir_candidate):
|
if len(kde4dir_candidate) == 0 or returncode != 0 or \
|
||||||
|
not os.path.isabs(kde4dir_candidate):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
else:
|
else:
|
||||||
self.kdedir = kde4dir_candidate + '/share/autostart'
|
self.kdedir = kde4dir_candidate + '/share/autostart'
|
||||||
except (OSError, ValueError):
|
except (OSError, ValueError):
|
||||||
# If neither kde-config nor kde4-config are not present or
|
# If neither kde-config nor kde4-config are not present or
|
||||||
# return an error, then we can assume that kde isn't installed
|
# return an error, then we can assume that kde isn't installed
|
||||||
@@ -216,15 +222,12 @@ class configure(Command):
|
|||||||
self.initfilename = os.path.basename(self.initfile)
|
self.initfilename = os.path.basename(self.initfile)
|
||||||
self.wicdgroup = 'users'
|
self.wicdgroup = 'users'
|
||||||
|
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
if self.distro_detect_failed == True:
|
if self.distro_detect_failed and not self.no_install_init and \
|
||||||
if not self.no_install_init:
|
'FAIL' in [self.init, self.initfile]:
|
||||||
if self.init == 'FAIL' or self.initfile == 'FAIL':
|
print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \
|
||||||
print 'ERROR: Failed to detect distro. Configure cannot continue. ' + \
|
'Please specify --init and --initfile to continue with configuration.'
|
||||||
'Please specify --init and --initfile to continue with configuration.'
|
|
||||||
|
|
||||||
|
|
||||||
# loop through the argument definitions in user_options
|
# loop through the argument definitions in user_options
|
||||||
for argument in self.user_options:
|
for argument in self.user_options:
|
||||||
# argument name is the first item in the user_options list
|
# argument name is the first item in the user_options list
|
||||||
@@ -247,12 +250,15 @@ class configure(Command):
|
|||||||
values = list()
|
values = list()
|
||||||
for argument in self.user_options:
|
for argument in self.user_options:
|
||||||
if argument[0].endswith('='):
|
if argument[0].endswith('='):
|
||||||
print argument[0][:-1],'is',
|
cur_arg = argument[0][:-1]
|
||||||
print getattr(self, argument[0][:-1])
|
cur_arg_value = getattr(self, cur_arg)
|
||||||
values.append((argument[0][:-1], getattr(self, argument[0][:-1].replace('-','_'))))
|
print "%s is %s" % (cur_arg, cur_arg_value)
|
||||||
|
values.append((cur_arg, cur_arg_value.replace('-', '_')))
|
||||||
else:
|
else:
|
||||||
print "Found switch",argument,getattr(self, argument[0].replace('-','_'))
|
cur_arg = argument[0]
|
||||||
values.append((argument[0], bool(getattr(self, argument[0].replace('-','_')))))
|
cur_arg_value = getattr(self, cur_arg.replace('-', '_'))
|
||||||
|
print "Found switch %s %s" % (argument, cur_arg_value)
|
||||||
|
values.append((cur_arg, bool(cur_arg_value)))
|
||||||
|
|
||||||
print 'Replacing values in template files...'
|
print 'Replacing values in template files...'
|
||||||
for item in os.listdir('in'):
|
for item in os.listdir('in'):
|
||||||
@@ -265,7 +271,8 @@ class configure(Command):
|
|||||||
item_out = open(final_name, 'w')
|
item_out = open(final_name, 'w')
|
||||||
for line in item_in.readlines():
|
for line in item_in.readlines():
|
||||||
for item, value in values:
|
for item, value in values:
|
||||||
line = line.replace('%' + str(item.upper().replace('-','_')) + '%', str(value))
|
line = line.replace('%' + str(item.upper().replace('-','_')) + \
|
||||||
|
'%', str(value))
|
||||||
|
|
||||||
# other things to replace that aren't arguments
|
# other things to replace that aren't arguments
|
||||||
line = line.replace('%VERSION%', str(VERSION_NUM))
|
line = line.replace('%VERSION%', str(VERSION_NUM))
|
||||||
@@ -353,7 +360,8 @@ class get_translations(Command):
|
|||||||
shutil.move(pofile, lang_identifier+'.po')
|
shutil.move(pofile, lang_identifier+'.po')
|
||||||
print 'Got',lang_identifier
|
print 'Got',lang_identifier
|
||||||
os.makedirs('translations/'+lang_identifier+'/LC_MESSAGES')
|
os.makedirs('translations/'+lang_identifier+'/LC_MESSAGES')
|
||||||
os.system('msgfmt --output-file=translations/'+lang_identifier+'/LC_MESSAGES/wicd.mo '+lang_identifier+'.po')
|
os.system('msgfmt --output-file=translations/' + lang_identifier +
|
||||||
|
'/LC_MESSAGES/wicd.mo ' + lang_identifier + '.po')
|
||||||
os.remove(lang_identifier+'.po')
|
os.remove(lang_identifier+'.po')
|
||||||
|
|
||||||
|
|
||||||
@@ -373,7 +381,7 @@ class uninstall(Command):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import wpath
|
import wpath
|
||||||
except:
|
except ImportError:
|
||||||
print '''Error importing wpath.py. You can safely ignore this
|
print '''Error importing wpath.py. You can safely ignore this
|
||||||
message. It is probably because you haven't run python setup.py
|
message. It is probably because you haven't run python setup.py
|
||||||
configure yet or you are running it for the first time.'''
|
configure yet or you are running it for the first time.'''
|
||||||
@@ -400,22 +408,29 @@ try:
|
|||||||
(wpath.icons + '22x22/apps/', ['icons/22px/wicd-client.png']),
|
(wpath.icons + '22x22/apps/', ['icons/22px/wicd-client.png']),
|
||||||
(wpath.icons + '16x16/apps/', ['icons/16px/wicd-client.png']),
|
(wpath.icons + '16x16/apps/', ['icons/16px/wicd-client.png']),
|
||||||
(wpath.images, [('images/' + b) for b in os.listdir('images') if not b.startswith('.')]),
|
(wpath.images, [('images/' + b) for b in os.listdir('images') if not b.startswith('.')]),
|
||||||
(wpath.encryption, [('encryption/templates/' + b) for b in os.listdir('encryption/templates') if not b.startswith('.')]),
|
(wpath.encryption, [('encryption/templates/' + b) for b in
|
||||||
|
os.listdir('encryption/templates') if not b.startswith('.')]),
|
||||||
(wpath.networks, []),
|
(wpath.networks, []),
|
||||||
(wpath.bin, ['scripts/wicd-client', ]),
|
(wpath.bin, ['scripts/wicd-client', ]),
|
||||||
(wpath.sbin, ['scripts/wicd', ]),
|
(wpath.sbin, ['scripts/wicd', ]),
|
||||||
(wpath.share, ['data/wicd.glade', ]),
|
(wpath.share, ['data/wicd.glade', ]),
|
||||||
(wpath.lib, ['wicd/wicd-client.py', 'wicd/monitor.py', 'wicd/wicd-daemon.py', 'wicd/configscript.py', 'wicd/suspend.py', 'wicd/autoconnect.py']), #'wicd/wicd-gui.py',
|
(wpath.lib, ['wicd/wicd-client.py', 'wicd/monitor.py',
|
||||||
|
'wicd/wicd-daemon.py', 'wicd/configscript.py',
|
||||||
|
'wicd/suspend.py', 'wicd/autoconnect.py']),
|
||||||
(wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']),
|
(wpath.backends, ['wicd/backends/be-external.py', 'wicd/backends/be-ioctl.py']),
|
||||||
(wpath.autostart, ['other/wicd-tray.desktop', ]),
|
(wpath.autostart, ['other/wicd-tray.desktop', ]),
|
||||||
|
(wpath.scripts, []),
|
||||||
|
(wpath.disconnectscripts, []),
|
||||||
|
(wpath.preconnectscripts, []),
|
||||||
|
(wpath.postconnectscripts, []),
|
||||||
]
|
]
|
||||||
if not wpath.no_install_ncurses:
|
if not wpath.no_install_ncurses:
|
||||||
data.append(( wpath.lib, ['curses/curses_misc.py']))
|
data.append((wpath.lib, ['curses/curses_misc.py']))
|
||||||
data.append(( wpath.lib, ['curses/prefs_curses.py']))
|
data.append((wpath.lib, ['curses/prefs_curses.py']))
|
||||||
data.append(( wpath.lib, ['curses/wicd-curses.py']))
|
data.append((wpath.lib, ['curses/wicd-curses.py']))
|
||||||
data.append(( wpath.lib, ['curses/netentry_curses.py']))
|
data.append((wpath.lib, ['curses/netentry_curses.py']))
|
||||||
data.append(( wpath.lib, ['curses/configscript_curses.py']))
|
data.append((wpath.lib, ['curses/configscript_curses.py']))
|
||||||
data.append(( wpath.bin, ['scripts/wicd-curses']))
|
data.append((wpath.bin, ['scripts/wicd-curses']))
|
||||||
if not wpath.no_install_man:
|
if not wpath.no_install_man:
|
||||||
data.append(( wpath.mandir + 'man8/', ['man/wicd-curses.8']))
|
data.append(( wpath.mandir + 'man8/', ['man/wicd-curses.8']))
|
||||||
piddir = os.path.dirname(wpath.pidfile)
|
piddir = os.path.dirname(wpath.pidfile)
|
||||||
@@ -423,22 +438,23 @@ try:
|
|||||||
piddir += '/'
|
piddir += '/'
|
||||||
data.append (( piddir, [] ))
|
data.append (( piddir, [] ))
|
||||||
if not wpath.no_install_docs:
|
if not wpath.no_install_docs:
|
||||||
data.append(( wpath.docdir, [ 'INSTALL', 'LICENSE', 'AUTHORS', 'README', 'CHANGES','other/WHEREAREMYFILES' ]))
|
data.append((wpath.docdir, ['INSTALL', 'LICENSE', 'AUTHORS',
|
||||||
|
'README', 'CHANGES', 'other/WHEREAREMYFILES']))
|
||||||
if not wpath.no_install_kde:
|
if not wpath.no_install_kde:
|
||||||
data.append(( wpath.kdedir, [ 'other/wicd-tray.desktop' ]))
|
data.append((wpath.kdedir, ['other/wicd-tray.desktop']))
|
||||||
if not wpath.no_install_init:
|
if not wpath.no_install_init:
|
||||||
data.append(( wpath.init, [ wpath.initfile ]))
|
data.append((wpath.init, [ wpath.initfile ]))
|
||||||
if not wpath.no_install_man:
|
if not wpath.no_install_man:
|
||||||
data.append(( wpath.mandir + 'man8/', [ 'man/wicd.8' ]))
|
data.append((wpath.mandir + 'man8/', [ 'man/wicd.8' ]))
|
||||||
data.append(( wpath.mandir + 'man5/', [ 'man/wicd-manager-settings.conf.5' ]))
|
data.append((wpath.mandir + 'man5/', [ 'man/wicd-manager-settings.conf.5' ]))
|
||||||
data.append(( wpath.mandir + 'man5/', [ 'man/wicd-wired-settings.conf.5' ]))
|
data.append((wpath.mandir + 'man5/', [ 'man/wicd-wired-settings.conf.5' ]))
|
||||||
data.append(( wpath.mandir + 'man5/', [ 'man/wicd-wireless-settings.conf.5' ]))
|
data.append((wpath.mandir + 'man5/', [ 'man/wicd-wireless-settings.conf.5' ]))
|
||||||
data.append(( wpath.mandir + 'man1/', [ 'man/wicd-client.1' ]))
|
data.append((wpath.mandir + 'man1/', [ 'man/wicd-client.1' ]))
|
||||||
if not wpath.no_install_acpi:
|
if not wpath.no_install_acpi:
|
||||||
data.append(( wpath.resume, ['other/80-wicd-connect.sh' ]))
|
data.append((wpath.resume, ['other/80-wicd-connect.sh' ]))
|
||||||
data.append(( wpath.suspend, ['other/50-wicd-suspend.sh' ]))
|
data.append((wpath.suspend, ['other/50-wicd-suspend.sh' ]))
|
||||||
if not wpath.no_install_pmutils:
|
if not wpath.no_install_pmutils:
|
||||||
data.append(( wpath.pmutils, ['other/55wicd' ]))
|
data.append((wpath.pmutils, ['other/55wicd' ]))
|
||||||
print 'Using pid path', os.path.basename(wpath.pidfile)
|
print 'Using pid path', os.path.basename(wpath.pidfile)
|
||||||
print 'Language support for',
|
print 'Language support for',
|
||||||
for language in os.listdir('translations/'):
|
for language in os.listdir('translations/'):
|
||||||
@@ -448,22 +464,24 @@ try:
|
|||||||
if codes[0].lower() == codes[1].lower():
|
if codes[0].lower() == codes[1].lower():
|
||||||
short_language = codes[0].lower()
|
short_language = codes[0].lower()
|
||||||
print short_language,
|
print short_language,
|
||||||
data.append((wpath.translations + short_language + '/LC_MESSAGES/', ['translations/' + language + '/LC_MESSAGES/wicd.mo']))
|
data.append((wpath.translations + short_language + '/LC_MESSAGES/',
|
||||||
print
|
['translations/' + language + '/LC_MESSAGES/wicd.mo']))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print str(e)
|
print str(e)
|
||||||
print '''Error setting up data array. This is normal if
|
print '''Error setting up data array. This is normal if
|
||||||
python setup.py configure has not yet been run.'''
|
python setup.py configure has not yet been run.'''
|
||||||
|
|
||||||
|
|
||||||
wpactrl_ext = Extension(name = 'wpactrl', sources = ['depends/python-wpactrl/wpa_ctrl.c', 'depends/python-wpactrl/wpactrl.c'],
|
wpactrl_ext = Extension(name = 'wpactrl',
|
||||||
extra_compile_args = ["-fno-strict-aliasing"])
|
sources = ['depends/python-wpactrl/wpa_ctrl.c',
|
||||||
|
'depends/python-wpactrl/wpactrl.c'],
|
||||||
|
extra_compile_args = ["-fno-strict-aliasing"])
|
||||||
|
|
||||||
iwscan_ext = Extension(name = 'iwscan',
|
iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'],
|
||||||
libraries = ['iw'],
|
sources = ['depends/python-iwscan/pyiwscan.c'])
|
||||||
sources = ['depends/python-iwscan/pyiwscan.c'])
|
|
||||||
|
|
||||||
setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated},
|
setup(cmdclass={'configure' : configure, 'get_translations' : get_translations,
|
||||||
|
'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated},
|
||||||
name="Wicd",
|
name="Wicd",
|
||||||
version=VERSION_NUM,
|
version=VERSION_NUM,
|
||||||
description="A wireless and wired network manager",
|
description="A wireless and wired network manager",
|
||||||
@@ -476,16 +494,12 @@ encryption types, such as WPA and WEP. Wicd will automatically
|
|||||||
connect at startup to any preferred network within range.
|
connect at startup to any preferred network within range.
|
||||||
""",
|
""",
|
||||||
author="Adam Blackburn, Dan O'Reilly",
|
author="Adam Blackburn, Dan O'Reilly",
|
||||||
author_email="compwiz18@users.sourceforge.net, imdano@users.sourceforge.net",
|
author_email="compwiz18@users.sourceforge.net, oreilldf@gmail.com",
|
||||||
url="http://wicd.net",
|
url="http://wicd.net",
|
||||||
license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
|
license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
|
||||||
## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'],
|
py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools',
|
||||||
py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath',
|
'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager',
|
||||||
'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend',
|
'wicd.logfile', 'wicd.backend', 'wicd.configmanager', 'wicd.guiutil'],
|
||||||
'wicd.configmanager', 'wicd.guiutil'],
|
|
||||||
ext_modules=[iwscan_ext, wpactrl_ext],
|
ext_modules=[iwscan_ext, wpactrl_ext],
|
||||||
data_files=data
|
data_files=data
|
||||||
)
|
)
|
||||||
##print "Running post-install configuration..."
|
|
||||||
##os.system("other/postinst")
|
|
||||||
##print 'Done.'
|
|
||||||
|
|||||||
19
wicd/misc.py
19
wicd/misc.py
@@ -58,7 +58,7 @@ ROUTE = 2
|
|||||||
GKSUDO = 1
|
GKSUDO = 1
|
||||||
KDESU = 2
|
KDESU = 2
|
||||||
KTSUSS = 3
|
KTSUSS = 3
|
||||||
__sudo_dict = {
|
_sudo_dict = {
|
||||||
AUTO : "",
|
AUTO : "",
|
||||||
GKSUDO : "gksudo",
|
GKSUDO : "gksudo",
|
||||||
KDESU : "kdesu",
|
KDESU : "kdesu",
|
||||||
@@ -172,9 +172,20 @@ def WriteLine(my_file, text):
|
|||||||
""" write a line to a file """
|
""" write a line to a file """
|
||||||
my_file.write(text + "\n")
|
my_file.write(text + "\n")
|
||||||
|
|
||||||
def ExecuteScript(script):
|
def ExecuteScripts(scripts_dir, verbose=False):
|
||||||
|
""" Execute every executable file in a given directory. """
|
||||||
|
for obj in os.listdir(scripts_dir):
|
||||||
|
obj = os.path.abspath(os.path.join(scripts_dir, obj))
|
||||||
|
if os.path.isfile(obj) and os.access(obj, os.X_OK):
|
||||||
|
ExecuteScript(os.path.abspath(obj), verbose=verbose)
|
||||||
|
|
||||||
|
def ExecuteScript(script, verbose=False):
|
||||||
""" Execute a command and send its output to the bit bucket. """
|
""" Execute a command and send its output to the bit bucket. """
|
||||||
call("%s > /dev/null 2>&1" % script, shell=True)
|
if verbose:
|
||||||
|
print "Executing %s" % script
|
||||||
|
ret = call("%s > /dev/null 2>&1" % script, shell=True)
|
||||||
|
if verbose:
|
||||||
|
"%s returned %s" % (script, ret)
|
||||||
|
|
||||||
def ReadFile(filename):
|
def ReadFile(filename):
|
||||||
""" read in a file and return it's contents as a string """
|
""" read in a file and return it's contents as a string """
|
||||||
@@ -427,7 +438,7 @@ def get_sudo_cmd(msg, prog_num=0):
|
|||||||
def choose_sudo_prog(prog_num=0):
|
def choose_sudo_prog(prog_num=0):
|
||||||
""" Try to intelligently decide which graphical sudo program to use. """
|
""" Try to intelligently decide which graphical sudo program to use. """
|
||||||
if prog_num:
|
if prog_num:
|
||||||
return find_path(__sudo_dict[prog_num])
|
return find_path(_sudo_dict[prog_num])
|
||||||
desktop_env = detect_desktop_environment()
|
desktop_env = detect_desktop_environment()
|
||||||
env_path = os.environ['PATH'].split(":")
|
env_path = os.environ['PATH'].split(":")
|
||||||
paths = []
|
paths = []
|
||||||
|
|||||||
@@ -201,10 +201,12 @@ class Controller(object):
|
|||||||
def Disconnect(self, *args, **kargs):
|
def Disconnect(self, *args, **kargs):
|
||||||
""" Disconnect from the network. """
|
""" Disconnect from the network. """
|
||||||
iface = self.iface
|
iface = self.iface
|
||||||
if self.disconnect_script != None:
|
misc.ExecuteScripts(wpath.disconnectscripts, self.debug)
|
||||||
|
if self.disconnect_script:
|
||||||
print 'Running disconnect script'
|
print 'Running disconnect script'
|
||||||
misc.ExecuteScript(expand_script_macros(self.disconnect_script,
|
misc.ExecuteScript(expand_script_macros(self.disconnect_script,
|
||||||
'disconnection', *args))
|
'disconnection', *args),
|
||||||
|
self.debug)
|
||||||
iface.ReleaseDHCP()
|
iface.ReleaseDHCP()
|
||||||
iface.SetAddress('0.0.0.0')
|
iface.SetAddress('0.0.0.0')
|
||||||
iface.FlushRoutes()
|
iface.FlushRoutes()
|
||||||
@@ -367,6 +369,10 @@ class ConnectThread(threading.Thread):
|
|||||||
self.SetStatus('interface_down')
|
self.SetStatus('interface_down')
|
||||||
iface.Down()
|
iface.Down()
|
||||||
|
|
||||||
|
@abortable
|
||||||
|
def run_global_scripts_if_needed(self, script_dir):
|
||||||
|
misc.ExecuteScripts(script_dir, verbose=self.debug)
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'):
|
def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'):
|
||||||
""" Execute a given script if needed.
|
""" Execute a given script if needed.
|
||||||
@@ -378,7 +384,8 @@ class ConnectThread(threading.Thread):
|
|||||||
"""
|
"""
|
||||||
if script:
|
if script:
|
||||||
print 'Executing %s script' % (msg)
|
print 'Executing %s script' % (msg)
|
||||||
misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid))
|
misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid),
|
||||||
|
self.debug)
|
||||||
|
|
||||||
@abortable
|
@abortable
|
||||||
def flush_routes(self, iface):
|
def flush_routes(self, iface):
|
||||||
@@ -760,6 +767,7 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
self.is_connecting = True
|
self.is_connecting = True
|
||||||
|
|
||||||
# Run pre-connection script.
|
# Run pre-connection script.
|
||||||
|
self.run_global_scripts_if_needed(wpath.preconnectscripts)
|
||||||
self.run_script_if_needed(self.before_script, 'pre-connection',
|
self.run_script_if_needed(self.before_script, 'pre-connection',
|
||||||
self.network['bssid'], self.network['essid'])
|
self.network['bssid'], self.network['essid'])
|
||||||
|
|
||||||
@@ -802,6 +810,7 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
self.set_dns_addresses()
|
self.set_dns_addresses()
|
||||||
|
|
||||||
# Run post-connection script.
|
# Run post-connection script.
|
||||||
|
self.run_global_scripts_if_needed(wpath.postconnectscripts)
|
||||||
self.run_script_if_needed(self.after_script, 'post-connection',
|
self.run_script_if_needed(self.after_script, 'post-connection',
|
||||||
self.network['bssid'], self.network['essid'])
|
self.network['bssid'], self.network['essid'])
|
||||||
|
|
||||||
@@ -970,6 +979,7 @@ class WiredConnectThread(ConnectThread):
|
|||||||
self.is_connecting = True
|
self.is_connecting = True
|
||||||
|
|
||||||
# Run pre-connection script.
|
# Run pre-connection script.
|
||||||
|
self.run_global_scripts_if_needed(wpath.preconnectscripts)
|
||||||
self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
|
self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
|
||||||
'wired')
|
'wired')
|
||||||
|
|
||||||
@@ -988,6 +998,7 @@ class WiredConnectThread(ConnectThread):
|
|||||||
self.set_dns_addresses()
|
self.set_dns_addresses()
|
||||||
|
|
||||||
# Run post-connection script.
|
# Run post-connection script.
|
||||||
|
self.run_global_scripts_if_needed(wpath.postconnectscripts)
|
||||||
self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
|
self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
|
||||||
'wired')
|
'wired')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user