Exemple #1
0
 def layout(self, name):
     if not name:
         return None
     self._create_layout_templates()
     layout_path = os.path.join(self._folder, name.lower() + "_layout.bii")
     if os.path.exists(layout_path):
         return load(layout_path)
Exemple #2
0
    def _add_build_step(self):
        project_config = self._project_config_path()
        contents = file_utils.load(project_config)

        if '-Debug' in contents:
            file_utils.search_and_replace(project_config,
                                          '-Debug@build</name>',
                                          '@build</name>')
 def _read_header_contents(self, headers):
     headers_contents = []
     for header_file in headers:
         header_content = file_utils.load(
             os.path.join(self.paths.dep, header_file))
         headers_contents.append(
             clean_preprocessor_directives(header_content.rstrip()))
     return headers_contents
    def test_initialize(self):
        """ Presence of WS configuration files
        """
        self.user_cache.bii_ignore
        # default_bii_ignore.bii
        path = os.path.join(self.biicode_folder, 'ignore.bii')
        c = load(path)
        self.assertIn('# Format is as follows:', c)
        self.assertIn('# Hidden files', c)

        self.user_cache.default_policies
        path = os.path.join(self.biicode_folder, 'default_policies.bii')
        c = load(path)
        self.assertIn('# This file configures', c)

        self.user_cache.localdb
        path = os.path.join(self.biicode_folder, 'bii.db')
        self.assertTrue(os.path.exists(path), path + ' does not exist.')
Exemple #5
0
    def test_initialize(self):
        """ Presence of WS configuration files
        """
        self.user_cache.bii_ignore
        # default_bii_ignore.bii
        path = os.path.join(self.biicode_folder, 'ignore.bii')
        c = load(path)
        self.assertIn('# Format is as follows:', c)
        self.assertIn('# Hidden files', c)

        self.user_cache.default_policies
        path = os.path.join(self.biicode_folder, 'default_policies.bii')
        c = load(path)
        self.assertIn('# This file configures', c)

        self.user_cache.localdb
        path = os.path.join(self.biicode_folder, 'bii.db')
        self.assertTrue(os.path.exists(path), path + ' does not exist.')
Exemple #6
0
 def _layout(self):
     if self._current_layout is None:
         layout_path = os.path.join(self.bii, "layout.bii")
         if os.path.exists(layout_path):
             self._current_layout = parse_layout_conf(load(layout_path),
                                                      self.project_root)
         else:
             self._current_layout = default_layout
     return self._current_layout
Exemple #7
0
 def _layout(self):
     if self._current_layout is None:
         layout_path = os.path.join(self.bii, "layout.bii")
         if os.path.exists(layout_path):
             self._current_layout = parse_layout_conf(
                 load(layout_path), self.project_root)
         else:
             self._current_layout = default_layout
     return self._current_layout
Exemple #8
0
def _get_filters(bii_ignore, bii_ignores, root, files, subfolder):
    #Now get the bii_ignore
    parent_dir = os.path.dirname(root)
    current_bii_ignore = bii_ignores.get(parent_dir, bii_ignore)
    if 'ignore.bii' in files:
        ignorebii_path = os.path.join(root, 'ignore.bii')
        ignorebii = file_utils.load(ignorebii_path)

        current_bii_ignore = current_bii_ignore + BiiIgnore.loads(ignorebii, subfolder)
    bii_ignores[root] = current_bii_ignore
    return current_bii_ignore
Exemple #9
0
 def root_block(self, value):
     assert isinstance(value, BlockName)
     self._current_layout[ROOT_BLOCK] = value
     layout_path = os.path.join(self.bii, "layout.bii")
     layout = load(layout_path)
     new_layout = []
     for line in layout.splitlines():
         if ROOT_BLOCK not in line or AUTO_ROOT_BLOCK in line:
             new_layout.append(line)
     new_layout.append("%s: %s" % (ROOT_BLOCK, value))
     new_layout = os.linesep.join(new_layout)
     save(layout_path, new_layout)
Exemple #10
0
 def root_block(self, value):
     assert isinstance(value, BlockName)
     self._current_layout[ROOT_BLOCK] = value
     layout_path = os.path.join(self.bii, "layout.bii")
     layout = load(layout_path)
     new_layout = []
     for line in layout.splitlines():
         if ROOT_BLOCK not in line or AUTO_ROOT_BLOCK in line:
             new_layout.append(line)
     new_layout.append("%s: %s" % (ROOT_BLOCK, value))
     new_layout = os.linesep.join(new_layout)
     save(layout_path, new_layout)
Exemple #11
0
 def update_root_block(self):
     if self._bii_paths.auto_root_block:
         bii_config_path = os.path.join(self._bii_paths.project_root, "biicode.conf")
         parent = (None if not os.path.exists(bii_config_path) else
                   BiiConfig(Blob(load(bii_config_path)).bytes).parent)
         if parent:
             project_block = parent.block_name
         else:  # Get the root block name from user + folder
             project_name = self._bii_paths.project_name
             user = self._user_cache.username or "user"
             project_block = BlockName("%s/%s" % (user, project_name))
         self._bii_paths.root_block = project_block
Exemple #12
0
def _get_filters(bii_ignore, bii_ignores, root, files, subfolder):
    #Now get the bii_ignore
    parent_dir = os.path.dirname(root)
    current_bii_ignore = bii_ignores.get(parent_dir, bii_ignore)
    if 'ignore.bii' in files:
        ignorebii_path = os.path.join(root, 'ignore.bii')
        ignorebii = file_utils.load(ignorebii_path)

        current_bii_ignore = current_bii_ignore + BiiIgnore.loads(
            ignorebii, subfolder)
    bii_ignores[root] = current_bii_ignore
    return current_bii_ignore
Exemple #13
0
 def update_root_block(self):
     if self._bii_paths.auto_root_block:
         bii_config_path = os.path.join(self._bii_paths.project_root,
                                        "biicode.conf")
         parent = (None if not os.path.exists(bii_config_path) else
                   BiiConfig(Blob(load(bii_config_path)).bytes).parent)
         if parent:
             project_block = parent.block_name
         else:  # Get the root block name from user + folder
             project_name = self._bii_paths.project_name
             user = self._user_cache.username or "user"
             project_block = BlockName("%s/%s" % (user, project_name))
         self._bii_paths.root_block = project_block
Exemple #14
0
    def _add_src_dir_type(self):
        cproject_config = self._project_config_path('.cproject')
        tree = ElementTree.parse(cproject_config)

        if not tree.find(".//storageModule[@moduleId='org.eclipse.cdt.core.pathentry']/*[@path='blocks']"):
            storage_module = tree.find(".//storageModule[@moduleId='org.eclipse.cdt.core.pathentry']")
            src_type_element = ElementTree.fromstring(SRC_TYPE_DIR)
            storage_module.append(src_type_element)
            dep_type_element = ElementTree.fromstring(DEP_TYPE_DIR)
            storage_module.append(dep_type_element)
            tree.write(cproject_config)
            cproject_string = file_utils.load(cproject_config)
            cproject_string = "%s%s" % (XML_HEADER, cproject_string)
            file_utils.save(cproject_config, cproject_string)
Exemple #15
0
    def default_policies(self):
        """ Return default WS policies.

        @return: default workspace policies
        """
        path = os.path.join(self._folder, 'default_policies.bii')
        if not os.path.exists(path):
            # load hardcoded default policies: default_policies
            save(path, default_policies)
            return default_policies
        current_defaults = load(path)
        # Migration to new simple policies.bii format
        if current_defaults.lstrip().startswith("# This is the file"):
            current_defaults = default_policies
            save(path, default_policies)
        return current_defaults
Exemple #16
0
def install_cmake(user_io, bii_paths, interactive):
    # check if the one by biicode is valid
    cmake_path_file = bii_paths.cmake_path_file
    if os.path.exists(cmake_path_file) and _valid_cmake(
            load(cmake_path_file).strip(), user_io):
        return

    # Check if the one in path is valid
    if _valid_cmake("", user_io):
        return

    if interactive:
        # Do you have it installed elsewhere?
        while True:
            path = user_io.request_string(
                "If you have cmake > %s installed, please enter path" %
                _CMAKE_MIN_VERSION, "None")
            if path == "None":
                break
            if _valid_cmake(path, user_io):
                save(cmake_path_file, path)
                return

        # Do you want me to install a copy for biicode it?
        user_io.out.writeln(
            "CMake >= %s not found.\nIf you want, biicode can install a local copy"
            " of cmake for its use.\nIt won't interfere with your current install"
            " if any.\nIf you dont want it, just quit, install it yourself and "
            "re-run this setup to enter its path" % _CMAKE_MIN_VERSION,
            Color.BRIGHT_GREEN)
        install = user_io.request_boolean("Install local copy of cmake %s?" %
                                          _CMAKE_VERSION,
                                          default_option=True)
    else:
        user_io.out.warn(
            "You are running in non-interactive mode.\n"
            "A CMake local copy will be installed automatically.\n"
            "Please run with '-i' or '--interactive' for more options")
        install = True

    if install:
        cmake_install_path = _install_cmake(user_io, bii_paths)
        save(cmake_path_file, cmake_install_path)
        if not _valid_cmake(cmake_install_path, user_io):
            user_io.out.error("Something failed in the installation of cmake")
        else:
            user_io.out.success("CMake %s installed ok" % _CMAKE_VERSION)
Exemple #17
0
 def settings(self):
     """ Return Hive settings.
     If settings.bii not present, creates and initialize a default hive settings.bii
     """
     if self._settings is None:
         settings_path = self._bii_paths.settings
         if not os.path.exists(settings_path):        # CREATE new hive settings file
             settings = Settings()           # empty settings, only OS information
             save(settings_path, settings.dumps())    # save settings.bii
             self._settings = settings
         else:                               # LOAD existing settings.bii file
             try:
                 self._settings = Settings.loads(load(settings_path))
             except Exception as e:
                 raise ClientException('%s\nIn file %s'
                                       % (str(e), settings_path.replace('\\', '/')))
     return self._settings
Exemple #18
0
    def _add_src_dir_type(self):
        cproject_config = self._project_config_path('.cproject')
        tree = ElementTree.parse(cproject_config)

        if not tree.find(
                ".//storageModule[@moduleId='org.eclipse.cdt.core.pathentry']/*[@path='blocks']"
        ):
            storage_module = tree.find(
                ".//storageModule[@moduleId='org.eclipse.cdt.core.pathentry']")
            src_type_element = ElementTree.fromstring(SRC_TYPE_DIR)
            storage_module.append(src_type_element)
            dep_type_element = ElementTree.fromstring(DEP_TYPE_DIR)
            storage_module.append(dep_type_element)
            tree.write(cproject_config)
            cproject_string = file_utils.load(cproject_config)
            cproject_string = "%s%s" % (XML_HEADER, cproject_string)
            file_utils.save(cproject_config, cproject_string)
Exemple #19
0
def make_content(brl, lang=BiiType(UNKNOWN), read_file=True):
    '''Reads a test file as binary or systext depending on lang
    Parameters:
        brl: BlockCellName or ID
    '''
    if isinstance(lang, int):
        lang = BiiType(lang)
    binary = lang.is_binary()
    if isinstance(brl, basestring):
        name = '/'.join(brl.split('/')[1:])
        parser = parser_factory(lang, brl.split('/')[-1])
    if read_file:
        path = testfileutils.file_path(name)
        content = load(path)
        blob = Blob(content, is_binary=binary)
    else:
        blob = Blob("Blob example content", is_binary=binary)
    return Content(brl, blob, parser)
def make_content(brl, lang=BiiType(UNKNOWN), read_file=True):
    '''Reads a test file as binary or systext depending on lang
    Parameters:
        brl: BlockCellName or ID
    '''
    if isinstance(lang, int):
        lang = BiiType(lang)
    binary = lang.is_binary()
    if isinstance(brl, basestring):
        name = '/'.join(brl.split('/')[1:])
        parser = parser_factory(lang, brl.split('/')[-1])
    if read_file:
        path = testfileutils.file_path(name)
        content = load(path)
        blob = Blob(content, is_binary=binary)
    else:
        blob = Blob("Blob example content", is_binary=binary)
    return Content(brl, blob, parser)
    def _create_py_file(self, py_adapter_file_content, main):
        """Write python file content to src block root if content has changed.
        :param
            py_adapter_file_content: str with python adapter file content.
            main: BlockCellName of main target.
        """
        py_adapter_file_path = os.path.join(self.paths.src, main.block_name,
                                            main.cell_name.path, self.ADAPTER_FILE_NAME)
        file_content = Blob(py_adapter_file_content)

        try:
            old_content = Blob(file_utils.load(py_adapter_file_path))
        except:
            old_content = None

        if file_content != old_content:
            logger.debug("biipyc has changed or was created.")
            file_utils.save(py_adapter_file_path, file_content.load)
Exemple #22
0
 def save(self, folder_name, files):
     saved_blocks = set()
     project_block = self._bii_paths.root_block
     folder = self._bii_paths.get_src_folder(folder_name)
     for disk_bcn, load in files.iteritems():
         if disk_bcn.block_name == project_block:
             filepath = os.path.join(self._bii_paths.project_root, disk_bcn.cell_name)
         else:
             filepath = os.path.join(folder, disk_bcn)
         try:
             file_content = file_utils.load(filepath)
         except:
             file_content = None
         if file_content != load:
             if folder_name == DEP_DIR and disk_bcn.block_name not in saved_blocks:
                 saved_blocks.add(disk_bcn.block_name)
                 self._biiout.info("Saving files from: %s" % disk_bcn.block_name)
             file_utils.save(filepath, load)
Exemple #23
0
 def settings(self):
     """ Return Hive settings.
     If settings.bii not present, creates and initialize a default hive settings.bii
     """
     if self._settings is None:
         settings_path = self._bii_paths.settings
         if not os.path.exists(
                 settings_path):  # CREATE new hive settings file
             settings = Settings()  # empty settings, only OS information
             save(settings_path, settings.dumps())  # save settings.bii
             self._settings = settings
         else:  # LOAD existing settings.bii file
             try:
                 self._settings = Settings.loads(load(settings_path))
             except Exception as e:
                 raise ClientException(
                     '%s\nIn file %s' %
                     (str(e), settings_path.replace('\\', '/')))
     return self._settings
    def _create_py_file(self, py_adapter_file_content, main):
        """Write python file content to src block root if content has changed.
        :param
            py_adapter_file_content: str with python adapter file content.
            main: BlockCellName of main target.
        """
        py_adapter_file_path = os.path.join(self.paths.src, main.block_name,
                                            main.cell_name.path,
                                            self.ADAPTER_FILE_NAME)
        file_content = Blob(py_adapter_file_content)

        try:
            old_content = Blob(file_utils.load(py_adapter_file_path))
        except:
            old_content = None

        if file_content != old_content:
            logger.debug("biipyc has changed or was created.")
            file_utils.save(py_adapter_file_path, file_content.load)
Exemple #25
0
def install_cmake(user_io, bii_paths, interactive):
    # check if the one by biicode is valid
    cmake_path_file = bii_paths.cmake_path_file
    if os.path.exists(cmake_path_file) and _valid_cmake(load(cmake_path_file).strip(), user_io):
        return

    # Check if the one in path is valid
    if _valid_cmake("", user_io):
        return

    if interactive:
        # Do you have it installed elsewhere?
        while True:
            path = user_io.request_string("If you have cmake > %s installed, please enter path"
                                          % _CMAKE_MIN_VERSION, "None")
            if path == "None":
                break
            if _valid_cmake(path, user_io):
                save(cmake_path_file, path)
                return

        # Do you want me to install a copy for biicode it?
        user_io.out.writeln("CMake >= %s not found.\nIf you want, biicode can install a local copy"
                             " of cmake for its use.\nIt won't interfere with your current install"
                             " if any.\nIf you dont want it, just quit, install it yourself and "
                             "re-run this setup to enter its path" % _CMAKE_MIN_VERSION,
                             Color.BRIGHT_GREEN)
        install = user_io.request_boolean("Install local copy of cmake %s?" % _CMAKE_VERSION,
                                          default_option=True)
    else:
        user_io.out.warn("You are running in non-interactive mode.\n"
                         "A CMake local copy will be installed automatically.\n"
                         "Please run with '-i' or '--interactive' for more options")
        install = True

    if install:
        cmake_install_path = _install_cmake(user_io, bii_paths)
        save(cmake_path_file, cmake_install_path)
        if not _valid_cmake(cmake_install_path, user_io):
            user_io.out.error("Something failed in the installation of cmake")
        else:
            user_io.out.success("CMake %s installed ok" % _CMAKE_VERSION)
Exemple #26
0
 def save(self, folder_name, files):
     saved_blocks = set()
     project_block = self._bii_paths.root_block
     folder = self._bii_paths.get_src_folder(folder_name)
     for disk_bcn, load in files.iteritems():
         if disk_bcn.block_name == project_block:
             filepath = os.path.join(self._bii_paths.project_root,
                                     disk_bcn.cell_name)
         else:
             filepath = os.path.join(folder, disk_bcn)
         try:
             file_content = file_utils.load(filepath)
         except:
             file_content = None
         if file_content != load:
             if folder_name == DEP_DIR and disk_bcn.block_name not in saved_blocks:
                 saved_blocks.add(disk_bcn.block_name)
                 self._biiout.info("Saving files from: %s" %
                                   disk_bcn.block_name)
             file_utils.save(filepath, load)
Exemple #27
0
 def policies(self):
     if self._policies is None:
         policies_path = self._bii_paths.policies
         if not os.path.exists(policies_path):
             policies = self._user_cache.default_policies
             save(policies_path, policies)
         else:
             policies = load(policies_path)
             # Migration to new simple policies.bii format
             if policies.lstrip().startswith("# This is the file"):
                 self._biiout.warn("Upgrading your find policies to new format")
                 policies = self._user_cache.default_policies
                 save(policies_path, policies)
         if "YOUR_USER_NAME" in policies:
             user = self._user_cache.username
             if user is not None:
                 policies = policies.replace("YOUR_USER_NAME", user)
                 save(policies_path, policies)
         self._policies = Policy.loads(policies)
     return self._policies
Exemple #28
0
 def policies(self):
     if self._policies is None:
         policies_path = self._bii_paths.policies
         if not os.path.exists(policies_path):
             policies = self._user_cache.default_policies
             save(policies_path, policies)
         else:
             policies = load(policies_path)
             # Migration to new simple policies.bii format
             if policies.lstrip().startswith("# This is the file"):
                 self._biiout.warn(
                     "Upgrading your find policies to new format")
                 policies = self._user_cache.default_policies
                 save(policies_path, policies)
         if "YOUR_USER_NAME" in policies:
             user = self._user_cache.username
             if user is not None:
                 policies = policies.replace("YOUR_USER_NAME", user)
                 save(policies_path, policies)
         self._policies = Policy.loads(policies)
     return self._policies
Exemple #29
0
    def _add_linked_resources(self):
        project_config = self._project_config_path()

        cmake_path = self.paths.cmake.replace('\\', '/')
        bin_path = self.paths.bin.replace('\\', '/')
        blocks_path = self.paths.blocks.replace('\\', '/')
        deps_path = self.paths.deps.replace('\\', '/')
        bii_path = self.paths.bii.replace('\\', '/')
        linked_resources_xml = LINKED_RESOURCES.format(cmake_path, bin_path, blocks_path, bii_path,
                                                       deps_path)

        tree = ElementTree.fromstring(file_utils.load(project_config))

        link_names = tree.findall('linkedResources/*name')

        if not any(link_name.text == SRC_DIR for link_name in link_names):
            links_tree = ElementTree.fromstring(linked_resources_xml)
            linked_resources = tree.find(".//linkedResources")
            linked_resources.clear()
            for link in links_tree:
                linked_resources.append(link)
            et = ElementTree.ElementTree(tree)
            et.write(project_config, encoding='utf-8', xml_declaration=True)
Exemple #30
0
    def _add_linked_resources(self):
        project_config = self._project_config_path()

        cmake_path = self.paths.cmake.replace('\\', '/')
        bin_path = self.paths.bin.replace('\\', '/')
        blocks_path = self.paths.blocks.replace('\\', '/')
        deps_path = self.paths.deps.replace('\\', '/')
        bii_path = self.paths.bii.replace('\\', '/')
        linked_resources_xml = LINKED_RESOURCES.format(cmake_path, bin_path,
                                                       blocks_path, bii_path,
                                                       deps_path)

        tree = ElementTree.fromstring(file_utils.load(project_config))

        link_names = tree.findall('linkedResources/*name')

        if not any(link_name.text == SRC_DIR for link_name in link_names):
            links_tree = ElementTree.fromstring(linked_resources_xml)
            linked_resources = tree.find(".//linkedResources")
            linked_resources.clear()
            for link in links_tree:
                linked_resources.append(link)
            et = ElementTree.ElementTree(tree)
            et.write(project_config, encoding='utf-8', xml_declaration=True)
Exemple #31
0
    def _add_build_step(self):
        project_config = self._project_config_path()
        contents = file_utils.load(project_config)

        if '-Debug' in contents:
            file_utils.search_and_replace(project_config, '-Debug@build</name>', '@build</name>')
 def _read_header_contents(self, headers):
     headers_contents = []
     for header_file in headers:
         header_content = file_utils.load(os.path.join(self.paths.dep, header_file))
         headers_contents.append(clean_preprocessor_directives(header_content.rstrip()))
     return headers_contents
Exemple #33
0
def _get_cmake_command_path(bii_paths, command):
    if os.path.exists(bii_paths.cmake_path_file):
        return os.path.join(load(bii_paths.cmake_path_file).strip(), command)
    return command
def make_too_big_content(brl, lang=BiiType(UNKNOWN)):
    blob_load = load(testfileutils.file_path("limits/largefile.txt"))
    blob = Blob(blob_load, is_binary=True)
    parser = parser_factory(lang, brl.cell_name)
    return Content(brl, blob, parser)
Exemple #35
0
 def load(self, deserializer):
     data = load(self.config_file_path)
     info = pickle.loads(data)
     return deserializer().deserialize(info)
Exemple #36
0
 def load(self, deserializer):
     data = load(self.config_file_path)
     info = pickle.loads(data)
     return deserializer().deserialize(info)
Exemple #37
0
def _get_cmake_command_path(bii_paths, command):
    if os.path.exists(bii_paths.cmake_path_file):
        return os.path.join(load(bii_paths.cmake_path_file).strip(), command)
    return command
 def read_file(path):
     serial = file_utils.load(path)
     serial = BSON(serial)
     serial = BSON.decode(serial)
     srn = SystemResourceNames.deserialize(serial)
     return srn
Exemple #39
0
 def read_file(path):
     serial = file_utils.load(path)
     serial = BSON(serial)
     serial = BSON.decode(serial)
     srn = SystemResourceNames.deserialize(serial)
     return srn
Exemple #40
0
def make_too_big_content(brl, lang=BiiType(UNKNOWN)):
    blob_load = load(testfileutils.file_path("limits/largefile.txt"))
    blob = Blob(blob_load, is_binary=True)
    parser = parser_factory(lang, brl.cell_name)
    return Content(brl, blob, parser)
Exemple #41
0
 def bii_ignore(self):
     from biicode.client.workspace.bii_ignore import BiiIgnore, default_bii_ignore
     path = os.path.join(self._folder, 'ignore.bii')
     if not os.path.exists(path):
         save(path, default_bii_ignore)
     return BiiIgnore.loads(load(path))