示例#1
0
def process(message, options):
    """
        Policy/command processor.

        Arguments:
            message: Message object
            options: Options
    """

    dryrun = options.dryrun
  
    if message.type == "command":
        if message.command == "service.info":
            link = comar.Link()
            args = []
            for package in link.System.Service:
                type_, desc_, status_ = link.System.Service[package].info()
                args.append((package, desc_, status_))
            message.reply("service.info", args)
        elif message.command == "service.start":
            package = message.arguments[0]
            link = comar.Link()
            link.System.Service[package].start()
        elif message.command == "service.stop":
            package = message.arguments[0]
            link = comar.Link()
            link.System.Service[package].stop()
示例#2
0
def make_com():
    try:
        if ctx.comar_sockname:
            com = comar.Link(sockname=ctx.comar_sockname)
        else:
            com = comar.Link()
        return com
    except ImportError:
        raise Error(_("comar package is not fully installed"))
    except:
        raise Error(_("cannot connect to comar"))
示例#3
0
文件: probe.py 项目: pardus-anka/zorg
    def driverInfo(self, driver=None):
        if driver is None:
            driver = self.driver

        if driver is None:
            return {}

        link = comar.Link()
        packages = list(link.Xorg.Driver)
        for package in packages:
            try:
                info = link.Xorg.Driver[package].getInfo()
            except dbus.DBusException:
                continue
            alias = str(info["alias"])
            if alias == driver:
                info["package"] = package
                return info
        else:
            if driverExists(driver):
                info = {
                        "alias":        driver,
                        "xorg-module":  driver,
                        }
                return info
            else:
                return {}
示例#4
0
 def loadModule(self, parameters={}):
     # Initialize IPTables
     initializeIPTables()
     # Flush rules
     self.unloadModule()
     # Enable forwarding
     os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
     os.system("echo 1 > /proc/sys/net/ipv4/ip_dynaddr")
     # Load rules
     input = parameters.get("device-input", "")
     output = parameters.get("device-output", "")
     if input and output and input != output:
         in_name = input.split("_")[-1]
         out_name = output.split("_")[-1]
         execRule(
             "-A PARDUS-FW-MOD-SHARING -i %s -o %s -m state --state ESTABLISHED,RELATED -j ACCEPT"
             % (in_name, out_name))
         execRule("-A PARDUS-FW-MOD-SHARING -i %s -o %s -j ACCEPT" %
                  (out_name, in_name))
         execRule("-t nat -A PARDUS-POST-MOD-SHARING -o %s -j MASQUERADE" %
                  in_name)
         # Create local NAT profile
         import comar
         link = comar.Link()
         package, connection = findOrCreateConnection(link, output)
         link.Network.Link[package].setState(connection, "up")
         # Configure DHCP
         makeDHCPConf(out_name)
         # Start DHCP
         startService("dhcpd", restart=True)
示例#5
0
    def __init__(self,
                 packagedb=pisi.db.packagedb.PackageDB,
                 installdb=pisi.db.installdb.InstallDB()):
        Gtk.VBox.__init__(self)
        self.set_valign(Gtk.Align.CENTER)
        self.set_border_width(20)

        self.packagedb = packagedb
        self.installdb = installdb

        self.title = Gtk.Label("")
        self.pack_start(self.title, False, False, 0)

        self.progress = Gtk.ProgressBar()
        self.pack_start(self.progress, False, False, 0)

        self.operations = dict()

        self.update_ui()

        self.cb = None
        self.link = comar.Link()
        self.pmanager = self.link.System.Manager['pisi']
        self.link.listenSignals("System.Manager", self.pisi_callback)

        self.current_operations = None

        self.downloaded = 0
        self.current_package = None
示例#6
0
def getConnectionList():
    import comar
    link = comar.Link(socket=ctx.consts.dbus_socket_file)
    results = {}
    for package in link.Network.Link:
        results[package] = list(link.Network.Link[package].connections())
    return results
def get_link():
    """Connect to the COMAR daemon and return the link."""

    sockname = "/var/run/dbus/system_bus_socket"
    # YALI starts comar chrooted in the install target, but uses io
    # outside of the chroot environment, so Pisi needs to use a different
    # socket path to be able to connect true dbus (and comar).
    # (usually /var/run/dbus/system_bus_socket)
    if ctx.dbus_sockname:
        sockname = ctx.dbus_sockname

    alternate = False
    # If COMAR package is updated, all new configuration requests should be
    # made through new COMAR service. Passing alternate=True to Link() class
    # will ensure this.
    if ctx.comar_updated:
        alternate = True

    # This function is sometimes called when comar has recently started
    # or restarting after an update. So we give comar a chance to become
    # active in a reasonable time.
    timeout = 7
    exceptions = []
    while timeout > 0:
        try:
            link = comar.Link(socket=sockname, alternate=alternate)
            link.setLocale()
            return link
        except dbus.DBusException, e:
            exceptions.append(str(e))
        except Exception, e:
            exceptions.append(str(e))
示例#8
0
def get_pardus_part_info():
    pardus_part_info = []
    link = comar.Link(socket="/var/run/dbus/system_bus_socket")

    for i in get_pardus_partitions():
        path = "/mnt/rescue_disk/" + i[0]

        MOUNTED_PARDUS.add(path)
        if os.path.exists(path):
            flag = True
            for mounted in link.Disk.Manager["mudur"].getMounted():
                if str(mounted[1]) == path:
                    flag = False
                    if str(mounted[0]) != i[1]:
                        link.Disk.Manager["mudur"].umount(path)
                        link.Disk.Manager["mudur"].mount(i[1], path)
            if flag:
                link.Disk.Manager["mudur"].mount(i[1], path)
        else:
            os.makedirs(path)
            link.Disk.Manager["mudur"].mount(i[1], path)
        pardus_part_info.append([
            open(path + "/etc/pardus-release").read().rstrip("\n"), i[1], i[0],
            path
        ])

    return pardus_part_info
示例#9
0
文件: app.py 项目: pars-linux/uludag
    def __init__(self, parent=None):
        mainform.mainForm.__init__(self, parent)

        self.link = comar.Link()

        self.connect(self.buttonServices, SIGNAL("clicked()"),
                     self.getServices)
示例#10
0
    def __init__(self, path):
        self.path = path
        for _dir in SYS_DIRS:
            tgt = os.path.join(path, _dir)
            _dir = os.path.join("/", _dir)
            shell_tools.mount(_dir, tgt, param="--bind")

        shell_tools.chroot_run(path, "/sbin/ldconfig")
        shell_tools.chroot_run(path, "/sbin/update-environment")
        shell_tools.chroot_run(path, "/bin/service dbus start")

        self.socket_file = os.path.join(path, "var/run/dbus/system_bus_socket")

        dbus.bus.BusConnection(address_or_type="unix:path=%s" %
                               self.socket_file)
        self.link = comar.Link(socket=self.socket_file)
        self.baselayout = self.link.User.Manager["baselayout"]

        options = pisi.config.Options()
        options.yes_all = True
        options.ignore_dependency = True
        options.ignore_safety = True
        options.destdir = path

        #   dbus.SystemBus()

        pisi.api.set_dbus_sockname(self.socket_file)
        pisi.api.set_dbus_timeout(1200)
        pisi.api.set_options(options)
        pisi.api.set_comar(True)
        pisi.api.set_signal_handling(False)
示例#11
0
def getUserList():
    import comar
    link = comar.Link(socket=ctx.consts.dbus_socket_file)
    users = link.User.Manager["baselayout"].userList()
    return filter(
        lambda user: user[0] == 0 or (user[0] >= 1000 and user[0] <= 65000),
        users)
示例#12
0
def comarLinkInitialized():
    if ctx.flags.install_type == ctx.STEP_BASE or \
       ctx.flags.install_type == ctx.STEP_DEFAULT or \
       ctx.flags.install_type == ctx.STEP_RESCUE:
        if ctx.storage.storageset.active:
            ctx.socket = os.path.join(ctx.consts.target_dir, ctx.consts.dbus_socket)
            if not os.path.exists(ctx.socket):
                ctx.logger.debug("initializeComar: Dbus has not started")
                start_dbus()
                ctx.logger.debug("wait 2 second for dbus activation")
                time.sleep(2)
        else:
            ctx.logger.debug("initializeComar: StorageSet not activated")
            return False

    elif ctx.flags.install_type == ctx.STEP_FIRST_BOOT:
        ctx.socket = os.path.join(ctx.consts.root_dir, ctx.consts.dbus_socket)

    for i in range(40):
        try:
            ctx.logger.info("Trying to activate Comar")
            ctx.link = comar.Link(socket=ctx.socket)
        except dbus.DBusException:
            time.sleep(1)
            ctx.logger.debug("wait 1 second for dbus activation")
        else:
            if ctx.link:
                break

    if not ctx.link:
        ctx.logger.debug("Comar not activated")
        return False

    ctx.logger.info("Comar activated")
    return True
示例#13
0
 def removeRepo(self, r_name):
     try:
         link = comar.Link()
         link.setLocale()
         link.System.Manager["pisi"].removeRepository(r_name)
         return True
     except:
         return False
示例#14
0
def createConnection(package, device):
    import comar
    link = comar.Link()
    connection = _(MSG_CONNECTION_NAME)
    link.Network.Link[package].setDevice(connection, device)
    link.Network.Link[package].setAddress(connection, "manual", "172.16.0.1",
                                          "255.255.255.0", "")
    return connection
示例#15
0
def getServiceState(service):
    '''Get service state.'''
    link = comar.Link()
    link.call_package('System.Service.info', service)
    reply = link.read_cmd()
    return reply.command == 'result' and reply.data.split('\n')[1] in [
        'on', 'started'
    ]
示例#16
0
文件: service.py 项目: xning/mudur
def readyService(service):
    try:
        link = comar.Link()
        link.setLocale()
        link.useAgent(False)
        link.System.Service[service].ready()
    except dbus.DBusException, e:
        print _("Unable to start %s:") % service
        print "  %s" % e.args[0]
示例#17
0
    def addRepo(self, r_name, r_address):
        try:
            link = comar.Link()
            link.setLocale()
            link.System.Manager["pisi"].addRepository(r_name, r_address)
            return True

        except:
            return False
示例#18
0
def umount_pardus():
    link = comar.Link(socket="/var/run/dbus/system_bus_socket")
    for i in MOUNTED_PARDUS:
        while True:
            try:
                link.Disk.Manager["mudur"].umount(i)
                break
            except comar.dbus.DBusException:
                pass
示例#19
0
 def test5(self):
     result = {"step": 5, "isSucessful": False, "comment": ""}
     link = comar.Link()
     command = 'service bind restart'
     os.system(command)
     if link.System.Service[self.serviceName].info() == "started":
         result['isSucessful'] = True
     if not ['isSucessful']:
         result['comment'] = command + "hatalı çalıştı"
     self.resultList.append(result)
示例#20
0
    def process_IN_MODIFY(self, event):
        if event.pathname == os.path.join(SVXLINK_CONFIG_DIR, SVXLINK_CONF):

            now = datetime.datetime.now()
            print "[%s] Restarting svxlink server..." % now.strftime(
                "%Y-%m-%d %H:%M")

            link = comar.Link()
            link.System.Service["svxlink"].stop()
            link.System.Service["svxlink"].start()
示例#21
0
文件: service.py 项目: xning/mudur
def setServiceState(service, state, quiet=False):
    try:
        link = comar.Link()
        link.setLocale()
        link.useAgent(False)
        link.System.Service[service].setState(state)
    except dbus.DBusException, e:
        print _("Unable to set %s state:") % service
        print "  %s" % e.args[0]
        return
示例#22
0
文件: service.py 项目: xning/mudur
def reloadService(service, quiet=False):
    try:
        link = comar.Link()
        link.setLocale()
        link.useAgent(False)
        link.System.Service[service].reload()
    except dbus.DBusException, e:
        print _("Unable to reload %s:") % service
        print "  %s" % e.args[0]
        return
示例#23
0
文件: probe.py 项目: pardus-anka/zorg
    def enableDriver(self):
        package = self.driverInfo().get("package")
        oldpackage = enabledPackage()
        if package != oldpackage:
            link = comar.Link()
            if oldpackage and oldpackage.replace("-", "_") in list(link.Xorg.Driver):
                link.Xorg.Driver[oldpackage].disable(timeout=2**16-1)

            if package:
                link.Xorg.Driver[package].enable(timeout=2**16-1)
示例#24
0
 def removeRepo(self, r_name):
     if self.controlRepo():
         try:
             link = comar.Link()
             link.setLocale()
             link.System.Manager["pisi"].removeRepository(r_name)
             self.ui.information_label.setText(
                 "comak-repo deleted from your repo list.")
             return True
         except:
             return False
示例#25
0
def setServiceState(service, state):
    '''Set service state.'''
    link = comar.Link()
    link.call_package('System.Service.setState', service, {'state': state})
    link.read_cmd()

    if state == 'on':
        link.call_package('System.Service.start', service)
    else:
        link.call_package('System.Service.stop', service)
    link.read_cmd()
示例#26
0
 def addRepo(self, r_name, r_address):
     try:
         link = comar.Link()
         link.setLocale()
         link.System.Manager["pisi"].addRepository(r_name, r_address)
         self.ui.information_label.setText(
             "comak-repo added to your repo list.")
         self.__class__.screenSettings["hasChanged_repo"] = True
         return True
     except:
         return False
示例#27
0
 def test2(self):
     result = {"step": 2, "isSucessful": False, "comment": ""}
     link = comar.Link()
     command = 'service bind off'
     os.system(command)
     status = link.System.Service[self.serviceName].info()
     if status == "stopped" or status == "off":
         result['isSucessful'] = True
     if not result['isSucessful']:
         result['comment'] = command + " --- hatalı çalıştı"
     self.resultList.append(result)
示例#28
0
def reloadService(service, quiet=False):
    try:
        link = comar.Link()
        link.setLocale()
        link.useAgent(False)
        link.System.Service[service].reload()
    except dbus.DBusException as e:
        print(_("Unable to reload %s:") % service)
        print("  %s" % e.args[0])
        return
    if not quiet:
        print(_("Reloading %s") % service)
示例#29
0
    def __init__(self, parent):
        link = comar.Link()
        link.localize()
        self.link = link
        self.notifier = QSocketNotifier(link.sock.fileno(),
                                        QSocketNotifier.Read)
        self.connect(self.notifier, SIGNAL('activated(int)'), self.slotComar)

        formMain.__init__(self, parent)

        self.connect(self.pushTest, SIGNAL('clicked()'), self.slotTest)
        self.connect(self.pushHelp, SIGNAL('clicked()'), self.slotHelp)
示例#30
0
def rmmod(modules):
    loaded = loadedModules()

    for mod in modules:
        if mod.replace("-", "_") in loaded:
            link = comar.Link()
            try:
                link.Boot.Modules["module_init_tools"].unload(mod)
            except dbus.exceptions.DBusException:
                return False
    else:
        return True