Esempio n. 1
0
    def __init__(self, path='', prefix='scripts'):
        self.path = path
        self.prefix = prefix
        self.name = ''
        self.data = ''
        self.type = ''

        self._fp = filepath.FilePath(self.path)
        if self._fp.exists():
            basename = filepath.basename(self.path)
            extension = filepath.splitext(basename)[1]
            if not basename.startswith('.') and (extension == '.js'
                                                 or extension == '.dart'):
                file_variables = filevariables.FileVariables(self.path)
                filetype = file_variables.get_value('mamba-file-type')
                if filetype != 'mamba-javascript' and filetype != 'mamba-dart':
                    raise InvalidFile('File {} is not a valid JavaScript '
                                      'or Dart mamba file'.format(self.path))

                res = '{}/{}'.format(self.prefix, self._fp.basename())
                self.data = res
                self.name = self._fp.basename()
                self.type = ('text/javascript'
                             if extension == '.js' else 'text/dart')
            else:
                raise InvalidFileExtension(
                    'File {} has not a valid extension (.js or .dart)'.format(
                        self.path))
        else:
            raise FileDontExists('File {} does not exists'.format(self.path))
    def load(self, config_file):
        """Load the workflow rules from a Mamba .dc Python file

        :param config_file: The file where to load the configuration from
        :type config_file: str
        """

        module_name = filepath.splitext(filepath.basename(config_file))[0]

        if self.deployer_object and self.deployer_object.loaded:
            raise deployer.DeployerError(
                "Tried to load {module} deployer that is " "already loaded!".format(module=module_name)
            )

        self.deployer_name = module_name
        self.deployer_module = deployer.deployer_import(self.deployer_name, config_file)

        # load tasks
        docstring, new_style, classic, default = fabric_main.load_tasks_from_module(self.deployer_module)
        self.tasks = {
            "docstring": docstring,
            "functions": new_style if state.env.new_style_tasks else classic,
            "default": default,
        }

        state.commands.update(self.tasks.get("functions", {}))

        # abort if no commands found
        if not state.commands:
            log.err("No commands found ...aborting")
        else:
            for name in state.commands:
                execute(name)
Esempio n. 3
0
    def __init__(self, path='', prefix='styles'):
        self.path = path
        self.prefix = prefix
        self.name = ''
        self.data = ''

        self._fp = filepath.FilePath(self.path)
        if self._fp.exists():
            basename = filepath.basename(self.path)
            extension = filepath.splitext(basename)[1]
            if not basename.startswith('.') and (extension == '.css'
                                                 or extension == '.less'):
                file_variables = filevariables.FileVariables(self.path)
                filetype = file_variables.get_value('mamba-file-type')
                if filetype != 'mamba-css' and filetype != 'mamba-less':
                    raise InvalidFile(
                        'File {} is not a valid CSS or LESS mamba file'.format(
                            self.path))

                res = '{}/{}'.format(self.prefix, self._fp.basename())
                self.data = res
                self.name = self._fp.basename()
            else:
                raise InvalidFileExtension(
                    'File {} has not a valid extension (.css or .less)'.format(
                        self.path))
        else:
            raise FileDontExists('File {} does not exists'.format(self.path))
    def __init__(self, path="", prefix="styles"):
        self.path = path
        self.prefix = prefix
        self.name = ""
        self.data = ""
        self.less = False

        self._fp = filepath.FilePath(self.path)
        if self._fp.exists():
            basename = filepath.basename(self.path)
            extension = filepath.splitext(basename)[1]
            if not basename.startswith(".") and (extension == ".css" or extension == ".less"):
                file_variables = filevariables.FileVariables(self.path)
                filetype = file_variables.get_value("mamba-file-type")
                if filetype != "mamba-css" and filetype != "mamba-less":
                    raise InvalidFile("File {} is not a valid CSS or LESS mamba file".format(self.path))

                if filetype == "mamba-less":
                    self.less = True

                res = "/{}/{}".format(self.prefix, self._fp.basename())
                self.data = res
                self.name = self._fp.basename()
            else:
                raise InvalidFileExtension("File {} has not a valid extension (.css or .less)".format(self.path))
        else:
            raise FileDontExists("File {} does not exists".format(self.path))
Esempio n. 5
0
 def __notify(self, ignored, filepath, mask):
     if self.bounceTimer:
         return
     file, ext = filepath.splitext()
     print("[SkinAutoReloader] Detected a change to %s%s" % (file, ext))
     if ext == b".xml":
         self.bounceTimer = eTimer()
         self.bounceTimer.callback.append(self.__reloadSkin)
         self.bounceTimer.start(500, True)
Esempio n. 6
0
    def _valid_file(self, file_path, file_type):
        """Check if a file is a valid Mamba file
        """

        basename = filepath.basename(file_path)
        if filepath.splitext(basename)[1] == self._extension:
            filevars = filevariables.FileVariables(file_path)
            if filevars.get_value('mamba-file-type') == file_type:
                return True

        return False
Esempio n. 7
0
    def _valid_file(self, file_path, file_type):
        """Check if a file is a valid Mamba file
        """

        basename = filepath.basename(file_path)
        if filepath.splitext(basename)[1] == self._extension:
            filevars = filevariables.FileVariables(file_path)
            if filevars.get_value('mamba-file-type') == file_type:
                return True

        return False
Esempio n. 8
0
def _valid_file(config_file):
    """
    Return True if 'config_file' is a valid config file, otherwise return False

    :param config_file: the file to check
    :type config_file: str
    """

    basename = filepath.basename(config_file)
    if filepath.splitext(basename)[1] == '.dc':
        ftype = FileVariables(config_file).get_value('mamba-deployer')
        if ftype and ftype == 'fabric':
            return True

    return False
def _valid_file(config_file):
    """
    Return True if 'config_file' is a valid config file, otherwise return False

    :param config_file: the file to check
    :type config_file: str
    """

    basename = filepath.basename(config_file)
    if filepath.splitext(basename)[1] == ".dc":
        ftype = FileVariables(config_file).get_value("mamba-deployer")
        if ftype and ftype == "fabric":
            return True

    return False
Esempio n. 10
0
    def load(self, filename):
        """Loads a Mamba module

        :param filename: the module filname
        :type filename: str
        """

        if type(filename) is not str:
            filename = filename.path

        module_name = filepath.splitext(filepath.basename(filename))[0]
        module_path = '{}.{}'.format(
            self._modulize_store(),
            module_name
        )

        if module_name in self._modules:
            return

        objs = [module_name.capitalize()]
        temp_module = __import__(module_path, globals(), locals(), objs)
        # instance the object
        try:
            temp_object = getattr(temp_module, objs[0])()
        except AttributeError:
            for member in dir(temp_module):
                tmp_member = getattr(temp_module, member)

                if (type(tmp_member) is ExtensionPoint
                        or type(tmp_member).__name__ == 'MambaStorm'):
                    # make sure we are not instantiating incorrect objects
                    if tmp_member.__module__ == temp_module.__name__:
                        temp_object = tmp_member()
                        break

        temp_object.loaded = True

        self._modules.update({
            module_name: {
                'object': temp_object,
                'module': temp_module,
                'module_path': module_path
            }
        })
Esempio n. 11
0
    def _notify(self, ignore, file_path, mask):
        """Notifies the changes on resources file_path
        """

        if not GNU_LINUX:
            return

        if mask == inotify.IN_MODIFY:
            if not self.is_valid_file(file_path):
                return

            module = filepath.splitext(file_path.basename())[0]
            if module in self._modules:
                self.reload(module)

        if mask == inotify.IN_CREATE:
            if file_path.exists():
                if self.is_valid_file(file_path):
                    self.load(file_path)
Esempio n. 12
0
    def _notify(self, ignore, file_path, mask):
        """Notifies the changes on resources file_path
        """

        if not GNU_LINUX:
            return

        if mask == inotify.IN_MODIFY:
            if not self.is_valid_file(file_path):
                return

            module = filepath.splitext(file_path.basename())[0]
            if module in self._modules:
                self.reload(module)

        if mask == inotify.IN_CREATE:
            if file_path.exists():
                if self.is_valid_file(file_path):
                    self.load(file_path)
Esempio n. 13
0
    def load(self, filename):
        """Loads a Mamba module

        :param filename: the module filname
        :type filename: str
        """

        if type(filename) is not str:
            filename = filename.path

        module_name = filepath.splitext(filepath.basename(filename))[0]
        module_path = '{}.{}'.format(self._modulize_store(), module_name)

        if module_name in self._modules:
            return

        objs = [module_name.capitalize()]
        temp_module = __import__(module_path, globals(), locals(), objs)
        # instance the object
        try:
            temp_object = getattr(temp_module, objs[0])()
        except AttributeError:
            for member in dir(temp_module):
                tmp_member = getattr(temp_module, member)

                if (type(tmp_member) is ExtensionPoint
                        or type(tmp_member).__name__ == 'MambaStorm'):
                    # make sure we are not instantiating incorrect objects
                    if tmp_member.__module__ == temp_module.__name__:
                        temp_object = tmp_member()
                        break

        temp_object.loaded = True

        self._modules.update({
            module_name: {
                'object': temp_object,
                'module': temp_module,
                'module_path': module_path
            }
        })
Esempio n. 14
0
    def load(self, config_file):
        """Load the workflow rules from a Mamba .dc Python file

        :param config_file: The file where to load the configuration from
        :type config_file: str
        """

        module_name = filepath.splitext(filepath.basename(config_file))[0]

        if self.deployer_object and self.deployer_object.loaded:
            raise deployer.DeployerError(
                'Tried to load {module} deployer that is '
                'already loaded!'.format(module=module_name)
            )

        self.deployer_name = module_name
        self.deployer_module = deployer.deployer_import(
            self.deployer_name,
            config_file
        )

        # load tasks
        docstring, new_style, classic, default = (
            fabric_main.load_tasks_from_module(self.deployer_module)
        )
        self.tasks = {
            'docstring': docstring,
            'functions': new_style if state.env.new_style_tasks else classic,
            'default': default
        }

        state.commands.update(self.tasks.get('functions', {}))

        # abort if no commands found
        if not state.commands:
            log.err('No commands found ...aborting')
        else:
            for name in state.commands:
                execute(name)
Esempio n. 15
0
    def __init__(self, path='', prefix='scripts'):
        self.path = path
        self.prefix = prefix
        self.name = ''
        self.data = ''
        self.type = ''

        self._fp = filepath.FilePath(self.path)
        if self._fp.exists():
            basename = filepath.basename(self.path)
            extension = filepath.splitext(basename)[1]
            if not basename.startswith('.') and (extension == '.js' or
                                                 extension == '.dart'):
                file_variables = filevariables.FileVariables(self.path)
                filetype = file_variables.get_value('mamba-file-type')
                if filetype != 'mamba-javascript' and filetype != 'mamba-dart':
                    raise InvalidFile(
                        'File {} is not a valid JavaScript '
                        'or Dart mamba file'.format(self.path)
                    )

                res = '/{}/{}'.format(self.prefix, self._fp.basename())
                self.data = res
                self.name = self._fp.basename()
                self.type = ('text/javascript' if extension == '.js'
                             else 'text/dart')
            else:
                raise InvalidFileExtension(
                    'File {} has not a valid extension (.js or .dart)'.format(
                        self.path
                    )
                )
        else:
            raise FileDontExists(
                'File {} does not exists'.format(self.path)
            )