Example #1
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))
Example #2
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))
Example #3
0
    def enqueueConfiguration(self, ignored, filepath, mask):
        """
        Parse files matching the glob pattern and create future call
        """
        call = None
        if fnmatch.fnmatch(filepath.basename(), self._aapattern):
            try:
                cfg = Configuration(filepath.path)
            except Exception as e:
                log.msg ("### Unable to create configuration object from provided config file!")
                log.msg ('### %s' % str(e))
                return

                
            call = call_at(
                cfg.start_time,
                self.applyConfiguration,
                cfg
            )

        if call and filepath.path in self._configs and self._configs[filepath.path].active():
            log.msg("Rescheduling config update %s" % (filepath.path))
            self._configs[filepath.path].cancel()
            self._configs[filepath.path] = call
            self._configobjs[filepath.path] = cfg
        elif call and filepath.path not in self._configs:
            log.msg("Scheduling config update %s" % (filepath.path))
            self._configs[filepath.path] = call
            self._configobjs[filepath.path] = cfg
        else:
            log.msg("Ignoring config update %s" % (filepath.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)
    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))
Example #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
Example #7
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)
Example #8
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
Example #9
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)
Example #10
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
Example #12
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
            }
        })
Example #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
            }
        })
Example #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)
Example #15
0
    def process_event(self, ignore, filepath, mask, library, dir_path):
        # Raised events use real paths, and in the libraries, paths follow
        # symlinks on directories. Therefore, paths must be fixed to use
        # symlinks before being passed on to the library. This is why
        # the library dir_path is passed and used here.
        session = Session()
        filename = filepath.basename().decode("utf-8")
        fpath = os.path.join(dir_path, filename)

        log.debug("inotify: %s event on '%s'" %
                  (twisted.internet.inotify.humanReadableMask(mask), fpath))

        path, name = os.path.split(fpath)

        if mask & twisted.internet.inotify.IN_CREATE:
            if self.__isdir_event(mask)\
                    or self.__occured_on_dirlink(library, fpath):
                library.crawl_directory(path, name)
        elif mask & twisted.internet.inotify.IN_DELETE:
            if self.__isdir_event(mask)\
                    or self.__occured_on_dirlink(library, fpath):
                library.remove_directory(path, name)
            elif not self.__isdir_event(mask):
                library.remove_file(path, name)
        elif mask & twisted.internet.inotify.IN_MOVED_FROM:
            if not self.__isdir_event(mask):
                library.remove_file(path, name)
            else:
                library.remove_directory(path, name)
        elif mask & twisted.internet.inotify.IN_MOVED_TO:
            if not self.__isdir_event(mask):
                library.update_file(path, name)
            else:
                library.crawl_directory(path, name)
        elif mask & twisted.internet.inotify.IN_CLOSE_WRITE:
            library.update_file(path, name)

        session.commit()
        session.close()
Example #16
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)
            )
Example #17
0
    def enqueueObservation(self, ignored, filepath, mask):
        """
        Parse files matching the glob pattern and create future call
        """
        call = None
        if fnmatch.fnmatch(filepath.basename(), self._fnpattern):
            obs = Observation(filepath.path)
            if not obs.is_valid():
                log.msg("Invalid %s; ignoring" % (obs))
                return

            key = hash(obs)

            # Special check only for HBA observations.
            if obs.antenna_array == "HBA":
                # Check if the AARTFAAC configuration corresponding to the time of
                # the observation has a matching specification in terms of 
                # antenna array. Added to allow specific HBA observations.
    
                # Find the config among those available, that would be active when
                #  this observation is scheduled.
                log.msg ('<-- Found an HBA observation. Checking for corresponding config.')
                min_timdel= datetime.timedelta.max
                ind = None
                for k, v in self._configs.iteritems():
                    cfgtim = datetime.datetime.fromtimestamp(v.getTime())
                    log.msg ('    cfgtim: %s, obs time: %s' % (cfgtim, obs.start_time));
                    if cfgtim > obs.start_time:
                        break
                    timdel = obs.start_time - cfgtim
                    if timdel < min_timdel:
                        min_timdel = timdel;
                        ind = k;
                    
                if ind:
                    log.msg ('    Closest AARTFAAC config. (%s) is %s seconds before observation. key: %s' % 
                                (str(self._configs[ind]), min_timdel.seconds, ind))

                    # Ignore this observation if no suitable config is found.
                    if not "hba" in self._configobjs[ind]._config:
                        call = None
                        log.msg("    Ignoring config %s: mode: %s. Active config during obs. is not HBA."
                            % (filepath.path, self._configobjs[ind]._config["hba"]["modes"]))
                        return
                else:
                    call = None
                    log.msg("    Ignoring config %s: No suitable HBA AARTFAAC config found." % filepath.path)
                    return
                    
                                   
            if key in self._parsets and self._parsets[key].active():
                log.msg("Already scheduled %s; ignoring" % (obs))
            elif key not in self._parsets:
                call = call_at_to(obs.start_time - datetime.timedelta(seconds=self.PRE_TIME), 
                            obs.end_time, self.processObservation, obs)
                if call:
                    log.msg("Scheduling observation %s (%s)" % (obs, filepath.path))
                    self._parsets[key] = call
                    call_at(obs.end_time - datetime.timedelta(seconds=60), self.endObservation, obs)
        else:
            log.msg("Ignoring %s" % (filepath.path))