Kaydet (Commit) 32c2d57d authored tarafından Bahadır Kandemir's avatar Bahadır Kandemir

Moved common network code under comar.network

üst 4f2fd6b0
2009-05-10 Bahadır Kandemir <bahadir@pardus.org.tr>
* network: Moved common network code under comar.network module.
2009-05-07 Bahadır Kandemir <bahadir@pardus.org.tr> 2009-05-07 Bahadır Kandemir <bahadir@pardus.org.tr>
* api: Do nothing if PolicyKit is unavailable * api: Do nothing if PolicyKit is unavailable
......
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2006-2008, TUBITAK/UEKAE # Copyright (C) 2006-2009, TUBITAK/UEKAE
# #
# This program is free software; you can redistribute it and/or modify it # This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
......
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006-2009, TUBITAK/UEKAE
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#
"""network module provides network management utils."""
import os
from pardus import iniutils
NET_PATH = "/etc/network"
NET_STACK = "baselayout"
INI = iniutils.iniParser(os.path.join(NET_PATH, script()))
def listProfiles():
try:
return INI.listSections()
except iniutils.iniParserError:
return []
class Profile:
def __init__(self, name):
self.name = name
try:
self.info = INI.getSection(name)
except iniutils.iniParserError:
self.info = {}
def delete(self):
INI.removeSection(self.name)
def save(self, no_notify=False):
is_new = self.name not in listProfiles()
INI.setSection(self.name, self.info)
if no_notify:
return
if is_new:
notify("Network.Link", "connectionChanged", ("added", self.name))
else:
notify("Network.Link", "connectionChanged", ("changed", self.name))
class AccessPoint:
def __init__(self, id=None):
self.ssid = ""
self.mode = ""
self.mac = ""
self.encryption = "none"
self.qual = ""
self.protocol = ""
self.channel = ""
if id:
if " (" in id and id.endswith(")"):
self.ssid, rest = id.split(" (", 1)
self.mode, self.mac = rest.split(" ", 1)
self.mac = self.mac[:-1]
else:
self.ssid = id
def id(self):
d = {
"remote": self.ssid,
"mode": self.mode,
"mac": self.mac,
"encryption": self.encryption,
"quality": self.qual,
"protocol": self.protocol,
"channel": self.channel,
}
return d
def stopSameDevice(name):
from csl import setState
profile = Profile(name)
device = profile.info["device"]
for pn in listProfiles():
if pn == name:
continue
pro = Profile(pn)
if pro.info["device"] == device:
setState(pn, "down")
def registerNameServers(profile, iface):
name_mode = profile.info.get("name_mode", "default")
name_servers = []
name_domain = ""
if name_mode == "auto":
for server in iface.autoNameServers():
name_servers.append(server)
name_domain = iface.autoNameSearch()
elif name_mode == "custom":
for server in profile.info.get("name_server", ",").split():
if server.strip():
name_servers.append(server.strip())
elif name_mode == "default":
name_servers = call(NET_STACK, "Network.Stack", "getNameServers")
call(NET_STACK, "Network.Stack", "registerNameServers", (iface.name, name_servers, name_domain))
def unregisterNameServers(iface):
call(NET_STACK, "Network.Stack", "unregisterNameServers", (iface.name, [], ""))
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2006-2008, TUBITAK/UEKAE # Copyright (C) 2006-2009, TUBITAK/UEKAE
# #
# This program is free software; you can redistribute it and/or modify it under # This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free # the terms of the GNU General Public License as published by the Free
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# Please read the COPYING file. # Please read the COPYING file.
# #
"""serviceutils module provides service management utils.""" """service module provides service management utils."""
import os import os
......
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2006-2008, TUBITAK/UEKAE # Copyright (C) 2006-2009, TUBITAK/UEKAE
# #
# This program is free software; you can redistribute it and/or modify it # This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
......
...@@ -16,7 +16,7 @@ import shutil ...@@ -16,7 +16,7 @@ import shutil
from distutils.core import setup from distutils.core import setup
from distutils.command.install import install from distutils.command.install import install
version = "2.1.3" version = "2.3.0"
distfiles = """ distfiles = """
setup.py setup.py
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment