示例#1
0
    def _process_template(self):
        """Prepare the template to write/dump
        """

        sep = filepath.os.sep  # windows needs '\\' as separator
        controller_template = Template(
            filepath.FilePath('{}/templates/controller.tpl'.format('/'.join(
                filepath.dirname(__file__).split(sep)[:-1]))).open('r').read())

        if self.options.subOptions.opts['classname'] is None:
            classname = self.options.subOptions.opts['name']
        else:
            classname = self.options.subOptions.opts['classname']

        args = {
            'year': datetime.datetime.now().year,
            'controller_name': self.options.subOptions.opts['name'],
            'platforms': self.options.subOptions.opts['platforms'],
            'synopsis': self.options.subOptions.opts['description'],
            'author': self.options.subOptions.opts['author'],
            'author_email': self.options.subOptions.opts['email'],
            'synopsis': self.options.subOptions.opts['description'],
            'controller_class': classname,
            'register_path': self.options.subOptions.opts['route']
        }

        return controller_template.safe_substitute(**args)
示例#2
0
    def _process_template(self):
        """Prepare the template to write/dump
        """

        sep = filepath.os.sep  # windows needs '\\' as separator
        controller_template = Template(
            filepath.FilePath('{}/templates/model.tpl'.format('/'.join(
                filepath.dirname(__file__).split(sep)[:-1]))).open('r').read())

        if self.options.subOptions.opts['classname'] is None:
            classname = self.options.subOptions.opts['name']
        else:
            classname = self.options.subOptions.opts['classname']

        if self.options.subOptions.opts['noschema'] != 0:
            class_properties = '__mamba_schema__ = False\n'
        else:
            class_properties = ''

        args = {
            'model_table': self.options.subOptions.opts['model_table'],
            'model_properties': self.model_properties,
            'class_properties': class_properties,
            'year': datetime.datetime.now().year,
            'model_name': self.options.subOptions.opts['name'],
            'platforms': self.options.subOptions.opts['platforms'],
            'synopsis': self.options.subOptions.opts['description'],
            'author': self.options.subOptions.opts['author'],
            'author_email': self.options.subOptions.opts['email'],
            'synopsis': self.options.subOptions.opts['description'],
            'model_class': classname,
        }

        return controller_template.safe_substitute(**args)
示例#3
0
    def _process_template(self):
        """Prepare the template to write/dump
        """

        sep = filepath.os.sep  # windows needs '\\' as separator
        controller_template = Template(
            filepath.FilePath('{}/templates/controller.tpl'.format(
                '/'.join(filepath.dirname(__file__).split(sep)[:-1])
            )).open('r').read()
        )

        if self.options.subOptions.opts['classname'] is None:
            classname = self.options.subOptions.opts['name']
        else:
            classname = self.options.subOptions.opts['classname']

        args = {
            'year': datetime.datetime.now().year,
            'controller_name': self.options.subOptions.opts['name'],
            'platforms': self.options.subOptions.opts['platforms'],
            'synopsis': self.options.subOptions.opts['description'],
            'author': self.options.subOptions.opts['author'],
            'author_email': self.options.subOptions.opts['email'],
            'synopsis': self.options.subOptions.opts['description'],
            'controller_class': classname,
            'register_path': self.options.subOptions.opts['route']
        }

        return controller_template.safe_substitute(**args)
示例#4
0
    def notify(self, unknown, filepath, mask):
        logger.debug("event %s on %s" % (", ".join(inotify.humanReadableMask(mask)), filepath))

        basename = filepath.basename()
        if not basename.endswith(config.GROWING_FILE_SUFFIX):
            return
        path = os.path.join(filepath.dirname(), basename)
        if mask == inotify.IN_CREATE:
            self.handle_in_create(path)
        elif mask == inotify.IN_DELETE:
            self.handle_in_delete(path)
示例#5
0
    def notify(self, unknown, filepath, mask):
        logger.debug('event %s on %s' %
                     (', '.join(inotify.humanReadableMask(mask)), filepath))

        basename = filepath.basename()
        if not basename.endswith(config.GROWING_FILE_SUFFIX):
            return
        path = os.path.join(filepath.dirname(), basename)
        if mask == inotify.IN_CREATE:
            self.handle_in_create(path)
        elif mask == inotify.IN_DELETE:
            self.handle_in_delete(path)
示例#6
0
    def _load_template_from_mamba(self, template):
        """
        Load a template from the installed mamba directory

        :param template: the template name
        :type template: str
        """

        # windows need '\\' as path separator
        sep = filepath.os.sep
        return Template(
            filepath.FilePath('{}/templates/{}'.format(
                '/'.join(filepath.dirname(__file__).split(sep)[:-1]),
                template if template.endswith('.tpl') else
                '{}.tpl'.format(template))).open('r').read())
示例#7
0
文件: _package.py 项目: aroshni/mamba
    def _load_template_from_mamba(self, template):
        """
        Load a template from the installed mamba directory

        :param template: the template name
        :type template: str
        """

        # windows need '\\' as path separator
        sep = filepath.os.sep
        return Template(
            filepath.FilePath('{}/templates/{}'.format(
                '/'.join(filepath.dirname(__file__).split(sep)[:-1]),
                template if template.endswith('.tpl') else '{}.tpl'.format(
                    template
                )
            )).open('rb' if template.endswith('.ico') else 'r').read()
        )
示例#8
0
    def _process_template(self):
        """Prepare the template to write/dump
        """

        sep = filepath.os.sep  # windows needs '\\' as separator
        view_template = Template(
            filepath.FilePath('{}/templates/view.tpl'.format('/'.join(
                filepath.dirname(__file__).split(sep)[:-1]))).open('r').read())

        args = {
            'year': datetime.datetime.now().year,
            'view_name': self.options.subOptions.opts['name'],
            'synopsis': self.options.subOptions.opts['description'],
            'author': self.options.subOptions.opts['author'],
            'author_email': self.options.subOptions['email']
        }

        return view_template.safe_substitute(**args)
示例#9
0
def _process_incoming_email(users_db, mail_couchdb_url_prefix, self, filepath, mask):
    if os.path.split(filepath.dirname())[-1]  == "new":
        logger.debug("Processing new mail at %s" % (filepath.path,))
        with filepath.open("r") as f:
            mail_data = f.read()
            mail = message_from_string(mail_data)
            owner = mail["To"]
            if owner is None:  # default to Delivered-To
                owner = mail["Delivered-To"]
            owner = owner.split("@")[0]
            owner = owner.split("+")[0]
            logger.debug("Mail owner: %s" % (owner,))

            logger.debug("%s received a new mail" % (owner,))
            d = users_db.queryByLoginOrAlias(owner)
            d.addCallback(_get_pubkey, (users_db))
            d.addCallback(_encrypt_message, (owner, mail_data))
            d.addCallback(_export_message, (mail_couchdb_url_prefix))
            d.addCallback(_conditional_remove, (filepath))
示例#10
0
文件: _view.py 项目: DamnWidget/mamba
    def _process_template(self):
        """Prepare the template to write/dump
        """

        sep = filepath.os.sep  # windows needs '\\' as separator
        view_template = Template(
            filepath.FilePath('{}/templates/view.tpl'.format(
                '/'.join(filepath.dirname(__file__).split(sep)[:-1])
            )).open('r').read()
        )

        args = {
            'year': datetime.datetime.now().year,
            'view_name': self.options.subOptions.opts['name'],
            'synopsis': self.options.subOptions.opts['description'],
            'author': self.options.subOptions.opts['author'],
            'author_email': self.options.subOptions['email']
        }

        return view_template.safe_substitute(**args)
示例#11
0
    def _process_incoming_email(self, otherself, filepath, mask):
        """
        Callback that processes incoming email.

        :param otherself: Watch object for the current callback from
                          inotify.
        :type otherself: twisted.internet.inotify._Watch
        :param filepath: Path of the file that changed
        :type filepath: twisted.python.filepath.FilePath
        :param mask: identifier for the type of change that triggered
                     this callback
        :type mask: int
        """
        try:
            while self._processing_skipped:
                log.msg("Waiting for the process of skipped mail to be done...")
                yield self.sleep(10)  # NO-OP
            if os.path.split(filepath.dirname())[-1]  == "new":
                yield self._step_process_mail_backend(filepath)
        except Exception as e:
            log.msg("Something went wrong while processing {0!r}: {1!r}"
                    .format(filepath, e))
示例#12
0
    def _process_incoming_email(self, otherself, filepath, mask):
        """
        Callback that processes incoming email

        @param otherself: Watch object for the current callback from
        inotify
        @type otherself: twisted.internet.inotify._Watch
        @param filepath: Path of the file that changed
        @type filepath: twisted.python.filepath.FilePath
        @param mask: identifier for the type of change that triggered
        this callback
        @type mask: int
        """
        if os.path.split(filepath.dirname())[-1]  == "new":
            log.msg("Processing new mail at %s" % (filepath.path,))
            with filepath.open("r") as f:
                mail_data = f.read()
                mail = message_from_string(mail_data)
                owner = mail["To"]
                if owner is None:  # default to Delivered-To
                    owner = mail["Delivered-To"]
                if owner is None:
                    log.err("Malformed mail, neither To: nor "
                            "Delivered-To: field")
                log.msg("Mail owner: %s" % (owner,))

                log.msg("%s received a new mail" % (owner,))
                dpubk = self._users_cdb.getPubKey(owner)
                duuid = self._users_cdb.queryByAddress(owner)
                d = DeferredList([dpubk, duuid])
                d.addCallbacks(self._gather_uuid_pubkey, log.err)
                d.addCallbacks(self._encrypt_message, log.err,
                               (owner, mail_data))
                d.addCallbacks(self._export_message, log.err)
                d.addCallbacks(self._conditional_remove, log.err,
                               (filepath,))
                d.addErrback(log.err)
示例#13
0
    def _process_template(self):
        """Prepare the template to write/dump
        """

        sep = filepath.os.sep  # windows needs '\\' as separator
        model_template = Template(
            filepath.FilePath('{}/templates/model.tpl'.format(
                '/'.join(filepath.dirname(__file__).split(sep)[:-1])
            )).open('r').read()
        )

        if self.options.subOptions.opts['classname'] is None:
            classname = self.options.subOptions.opts['name']
        else:
            classname = self.options.subOptions.opts['classname']

        if self.options.subOptions.opts['noschema'] != 0:
            class_properties = '__mamba_schema__ = False\n'
        else:
            class_properties = ''

        args = {
            'model_table': self.options.subOptions.opts['model_table'],
            'model_properties': self.model_properties,
            'class_properties': class_properties,
            'year': datetime.datetime.now().year,
            'model_name': self.options.subOptions.opts['name'],
            'platforms': self.options.subOptions.opts['platforms'],
            'synopsis': self.options.subOptions.opts['description'],
            'author': self.options.subOptions.opts['author'],
            'author_email': self.options.subOptions.opts['email'],
            'synopsis': self.options.subOptions.opts['description'],
            'model_class': classname,
        }

        return model_template.safe_substitute(**args)
示例#14
0
    def _process_incoming_email(self, otherself, filepath, mask):
        """
        Callback that processes incoming email.

        :param otherself: Watch object for the current callback from
                          inotify.
        :type otherself: twisted.internet.inotify._Watch
        :param filepath: Path of the file that changed
        :type filepath: twisted.python.filepath.FilePath
        :param mask: identifier for the type of change that triggered
                     this callback
        :type mask: int
        """
        try:
            while self._processing_skipped:
                log.msg("Waiting for the process of skipped mail to be "
                        "done...")
                yield self.sleep(10)  # NO-OP
            if os.path.split(filepath.dirname())[-1] == "new":
                yield self._step_process_mail_backend(filepath)
        except Exception as e:
            log.msg("Something went wrong while processing {0!r}: {1!r}"
                    .format(filepath, e))
            log.err()