当前位置: 首页>>代码示例>>Python>>正文


Python sysutils.exec_cmd函数代码示例

本文整理汇总了Python中modoboa.lib.sysutils.exec_cmd函数的典型用法代码示例。如果您正苦于以下问题:Python exec_cmd函数的具体用法?Python exec_cmd怎么用?Python exec_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了exec_cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_new_dkim_key

 def create_new_dkim_key(self, domain):
     """Create a new DKIM key."""
     storage_dir = param_tools.get_global_parameter("dkim_keys_storage_dir")
     pkey_path = os.path.join(storage_dir, "{}.pem".format(domain.name))
     key_size = (
         domain.dkim_key_length if domain.dkim_key_length
         else self.default_key_length)
     code, output = sysutils.exec_cmd(
         "openssl genrsa -out {} {}".format(pkey_path, key_size))
     if code:
         print("Failed to generate DKIM private key for domain {}: {}"
               .format(domain.name, smart_text(output)))
     domain.dkim_private_key_path = pkey_path
     code, output = sysutils.exec_cmd(
         "openssl rsa -in {} -pubout".format(pkey_path))
     if code:
         print("Failed to generate DKIM public key for domain {}: {}"
               .format(domain.name, smart_text(output)))
     public_key = ""
     for cpt, line in enumerate(smart_text(output).splitlines()):
         if cpt == 0 or line.startswith("-----"):
             continue
         public_key += line
     domain.dkim_public_key = public_key
     domain.save(update_fields=["dkim_public_key", "dkim_private_key_path"])
开发者ID:brucewu16899,项目名称:modoboa,代码行数:25,代码来源:_manage_dkim_keys.py

示例2: __init__

 def __init__(self, *args, **kwargs):
     super(AdminParametersForm, self).__init__(*args, **kwargs)
     self.field_widths = {
         "default_domain_quota": 2
     }
     hide_fields = False
     dpath = None
     code, output = exec_cmd("which dovecot")
     if not code:
         dpath = output.strip()
     else:
         known_paths = getattr(
             settings, "DOVECOT_LOOKUP_PATH",
             ("/usr/sbin/dovecot", "/usr/local/sbin/dovecot")
         )
         for fpath in known_paths:
             if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
                 dpath = fpath
     if dpath:
         try:
             code, version = exec_cmd("%s --version" % dpath)
         except OSError:
             hide_fields = True
         else:
             if code or not version.strip().startswith("2"):
                 hide_fields = True
     else:
         hide_fields = True
     if hide_fields:
         del self.fields["handle_mailboxes"]
         del self.fields["mailboxes_owner"]
开发者ID:isolution-de,项目名称:modoboa,代码行数:31,代码来源:app_settings.py

示例3: handle

    def handle(self, parsed_args):
        management.call_command(
            'startproject', parsed_args.name, verbosity=False
        )
        if os.path.exists("%(name)s/%(name)s" % {'name': parsed_args.name}):
            # Django 1.4+
            path = "%(name)s/%(name)s" % {'name': parsed_args.name}
            sys.path.append(parsed_args.name)
            django14 = True
        else:
            path = parsed_args.name
            sys.path.append(".")
            django14 = False

        t = Template(dbconn_tpl)
        default_conn = t.render(Context(self.ask_db_info()))
        amavis_conn = t.render(Context(self.ask_db_info('amavis'))) \
            if parsed_args.with_amavis else None

        allowed_host = raw_input(
            'Under which domain do you want to deploy modoboa? '
        )

        mod = __import__(parsed_args.name, globals(), locals(), ['settings'])
        tpl = self._render_template(
            "%s/settings.py.tpl" % self._templates_dir, {
                'default_conn': default_conn, 'amavis_conn': amavis_conn,
                'secret_key': mod.settings.SECRET_KEY,
                'name': parsed_args.name, 'django14': django14,
                'allowed_host': allowed_host
            }
        )
        fp = open("%s/settings.py" % path, "w")
        fp.write(tpl)
        fp.close()
        shutil.copyfile(
            "%s/urls.py.tpl" % self._templates_dir, "%s/urls.py" % path
        )
        os.mkdir("%s/media" % path)

        if parsed_args.syncdb:
            self._exec_django_command(
                "syncdb", parsed_args.name, '--noinput'
            )
            exec_cmd('sed -ri "s|^#(\s+\'south)|\\1|" %s/settings.py' % path)
            self._exec_django_command(
                "syncdb", parsed_args.name,
            )
            self._exec_django_command(
                'migrate', parsed_args.name, '--fake'
            )
            self._exec_django_command(
                "loaddata", parsed_args.name, 'initial_users.json'
            )

        if parsed_args.collectstatic:
            self._exec_django_command(
                "collectstatic", parsed_args.name, '--noinput'
            )
开发者ID:schiiz1,项目名称:modoboa,代码行数:59,代码来源:deploy.py

示例4: on

    def on(self):
        self.enabled = True
        self.save()

        self.__get_ext_instance()
        self.instance.load()
        self.instance.init()

        if self.instance.needs_media:
            path = os.path.join(settings.MEDIA_ROOT, self.name)
            exec_cmd("mkdir %s" % path)

        events.raiseEvent("ExtEnabled", self)
开发者ID:JHei,项目名称:modoboa,代码行数:13,代码来源:models.py

示例5: off

    def off(self):
        self.__get_ext_instance()
        if self.instance is None:
            return
        self.instance.destroy()

        self.enabled = False
        self.save()

        if self.instance.needs_media:
            path = os.path.join(settings.MEDIA_ROOT, self.name)
            exec_cmd("rm -r %s" % path)

        events.raiseEvent("ExtDisabled", self)
开发者ID:JHei,项目名称:modoboa,代码行数:14,代码来源:models.py

示例6: on

    def on(self, update_db=True):
        """Activate this extension."""
        if update_db:
            self.enabled = True
            self.save()

        self.__get_ext_instance()
        self.instance.load()
        self.instance.init()

        if self.instance.needs_media:
            path = os.path.join(settings.MEDIA_ROOT, self.name)
            exec_cmd("mkdir %s" % path)

        events.raiseEvent("ExtEnabled", self)
开发者ID:finid,项目名称:modoboa,代码行数:15,代码来源:models.py

示例7: mail_home

    def mail_home(self):
        """Retrieve the home directory of this mailbox.

        The home directory refers to the place on the file system
        where the mailbox data is stored.

        We ask dovecot to give us this information because there are
        several patterns to understand and we don't want to implement
        them.
        """
        admin_params = dict(param_tools.get_global_parameters("admin"))
        if not admin_params.get("handle_mailboxes"):
            return None
        if self.__mail_home is None:
            curuser = pwd.getpwuid(os.getuid()).pw_name
            mbowner = admin_params["mailboxes_owner"]
            options = {}
            if curuser != mbowner:
                options["sudo_user"] = mbowner
            code, output = exec_cmd(
                "doveadm user %s -f home" % self.full_address, **options
            )
            if code:
                raise lib_exceptions.InternalError(
                    _(u"Failed to retrieve mailbox location (%s)") % output)
            self.__mail_home = output.strip()
        return self.__mail_home
开发者ID:whyscream,项目名称:modoboa,代码行数:27,代码来源:mailbox.py

示例8: export

 def export(self, rrdfile, start, end):
     """Export data to XML using rrdtool and convert it to JSON."""
     result = []
     cmdargs = []
     for curve in self._curves:
         result += [{
             "name": curve.legend, "color": curve.color, "data": []
         }]
         cmdargs += curve.to_rrd_command_args(rrdfile)
     code = 0
     for extra_args in [" --showtime", ""]:
         cmd = "{} xport --start {} --end {}{} ".format(
             self.rrdtool_binary, str(start), str(end), extra_args)
         cmd += " ".join(cmdargs)
         if isinstance(cmd, unicode):
             cmd = cmd.encode("utf-8")
         code, output = exec_cmd(cmd)
         if code:
             continue
     if code:
         return []
     tree = etree.fromstring(output)
     for row in tree.xpath('/xport/data/row'):
         timestamp = int(row.find('t').text)
         for vindex, value in enumerate(row.findall('v')):
             if value.text == 'NaN':
                 result[vindex]['data'].append({'x': timestamp, 'y': 0})
             else:
                 result[vindex]['data'].append(
                     {'x': timestamp, 'y': float(value.text)}
                 )
     return result
开发者ID:Arvedui,项目名称:modoboa-stats,代码行数:32,代码来源:graphics.py

示例9: mail_home

    def mail_home(self):
        """Retrieve the home directory of this mailbox.

        The home directory refers to the place on the file system
        where the mailbox data is stored.

        We ask dovecot to give us this information because there are
        several patterns to understand and we don't want to implement
        them.
        """
        hm = parameters.get_admin("HANDLE_MAILBOXES", raise_error=False)
        if hm is None or hm == "no":
            return None
        if self.__mail_home is None:
            curuser = pwd.getpwuid(os.getuid()).pw_name
            mbowner = parameters.get_admin("MAILBOXES_OWNER")
            options = {}
            if curuser != mbowner:
                options['sudo_user'] = mbowner
            code, output = exec_cmd(
                "doveadm user %s -f home" % self.full_address, **options
            )
            if code:
                raise lib_exceptions.InternalError(
                    _("Failed to retrieve mailbox location (%s)" % output))
            self.__mail_home = output.strip()
        return self.__mail_home
开发者ID:cubicuboctahedron,项目名称:modoboa,代码行数:27,代码来源:mailbox.py

示例10: _learn

 def _learn(self, rcpt, msg, mtype):
     """Internal method to call the learning command."""
     if self._username is None:
         if self._recipient_db == "global":
             username = self._default_username
         else:
             mbox = self._get_mailbox_from_rcpt(rcpt)
             if mbox is None:
                 username = self._default_username
             if self._recipient_db == "domain":
                 username = mbox.domain.name
                 if username not in self._setup_cache and \
                    setup_manual_learning_for_domain(mbox.domain):
                     self._setup_cache[username] = True
             else:
                 username = mbox.full_address
                 if username not in self._setup_cache and \
                    setup_manual_learning_for_mbox(mbox):
                     self._setup_cache[username] = True
     else:
         username = self._username
     if username not in self._username_cache:
         self._username_cache.append(username)
     cmd = self._learn_cmd.format(mtype, username)
     code, output = exec_cmd(cmd, pinput=msg, **self._learn_cmd_kwargs)
     if code in self._expected_exit_codes:
         return True
     self.error = output
     return False
开发者ID:kaxdev,项目名称:modoboa,代码行数:29,代码来源:lib.py

示例11: export

 def export(self, rrdfile, start, end):
     """
     """
     result = []
     cmdargs = []
     for curve in self._curves:
         result += [{
             "name": curve.legend, "color": curve.color, "data": []
         }]
         cmdargs += curve.to_rrd_command_args(rrdfile)
     cmd = "rrdtool xport --start %s --end %s " % (str(start), str(end))
     cmd += " ".join(cmdargs)
     code, output = exec_cmd(cmd)
     if code:
         return []
     tree = etree.fromstring(output)
     for row in tree.xpath('/xport/data/row'):
         timestamp = int(row.find('t').text)
         for vindex, value in enumerate(row.findall('v')):
             if value.text == 'NaN':
                 result[vindex]['data'].append({'x': timestamp, 'y': 0})
             else:
                 result[vindex]['data'].append(
                     {'x': timestamp, 'y': float(value.text)}
                 )
     return result
开发者ID:isolution-de,项目名称:modoboa,代码行数:26,代码来源:graphics.py

示例12: test_silent

 def test_silent(self):
     dburl = "%s://%s:%[email protected]%s/%s" \
         % (self.dbtype, self.dbuser, self.dbpassword,
            self.dbhost, self.projname)
     cmd = "modoboa-admin.py deploy --syncdb --collectstatic --dburl %s --domain %s %s" \
         % (dburl, 'localhost', self.projname)
     code, output = exec_cmd(cmd, cwd=self.workdir)
     self.assertEqual(code, 0)
开发者ID:Marx86,项目名称:modoboa,代码行数:8,代码来源:install_from_scratch.py

示例13: tearDown

 def tearDown(self):
     path = os.path.join(self.workdir, self.projname)
     code, output = exec_cmd(
         "python manage.py test core lib admin limits postfix_relay_domains radicale",
         capture_output=False,
         cwd=path
     )
     self.assertEqual(code, 0)
开发者ID:JHei,项目名称:modoboa,代码行数:8,代码来源:install_from_scratch.py

示例14: tearDown

 def tearDown(self):
     path = os.path.join(self.workdir, self.projname)
     core_apps = ["modoboa.core", "modoboa.lib"]
     cmd = "python manage.py test {0}".format(
         " ".join(core_apps),
     )
     code, output = exec_cmd(cmd, capture_output=False, cwd=path)
     self.assertEqual(code, 0)
开发者ID:Norcoen,项目名称:modoboa,代码行数:8,代码来源:install_from_scratch.py

示例15: delete_mailbox

 def delete_mailbox(self, operation):
     if not os.path.exists(operation.argument):
         return
     code, output = exec_cmd(
         "rm -r %s" % operation.argument
     )
     if code:
         raise OperationError(output)
开发者ID:Tdey,项目名称:modoboa,代码行数:8,代码来源:handle_mailbox_operations.py


注:本文中的modoboa.lib.sysutils.exec_cmd函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。