예제 #1
0
    def __init__(self, root, layout, user_home):
        BiiPaths.__init__(self, root, user_home)

        os.mkdir(os.path.join(root, BII_DIR))  # bii/ folder
        save(os.path.join(root, BII_DIR, BII_HIVE_DB),
             '')  # fake database file
        save(os.path.join(root, BII_DIR, 'layout.bii'), layout)  # layout file
예제 #2
0
 def create_new_file(self, block_path, file_name, content=''):
     ''' Create main files with Hello World templates '''
     file_path = os.path.join(block_path, file_name)
     save(file_path, content)  # save method handles exceptions
     msg_succes = 'Success: created {file_name} file in {path}'
     self._biiout.success(
         msg_succes.format(file_name=file_name, path=block_path))
예제 #3
0
 def test_bad_location(self):
     bii_ignore = BiiIgnore.defaults()
     save(os.path.join(self.folder, 'User/mybadFile.cpp'), '')
     _ = walk_bii_folder(self.folder, bii_ignore, self.biiout)
     # Check that the system detected misplaced file
     self.assertIn("WARN: User/mybadFile.cpp is misplaced",
                   str(self.biiout))
예제 #4
0
 def _create_layout_templates(self):
     for name, content in {"simple": _simple_layout,
                           "clion": _clion_layout,
                           "tmp": _tmp_layout}.iteritems():
         layout_path = os.path.join(self._folder, "%s_layout.bii" % name)
         if not os.path.exists(layout_path):
             save(layout_path, content)
예제 #5
0
    def settings(self, value):
        """Set hive settings and save.

        :param value: new hive settings
        :type value: biicode.common.settings.settings.Settings

        """
        self._settings = value
        save(self._bii_paths.settings, value.dumps())
예제 #6
0
    def settings(self, value):
        """Set hive settings and save.

        :param value: new hive settings
        :type value: biicode.common.settings.settings.Settings

        """
        self._settings = value
        save(self._bii_paths.settings, value.dumps())
예제 #7
0
def create_noderunner(project_path, blocks_folder, deps_folder):
    if platform.system() == 'Windows':
        runner = "noderunner.bat"
    else:
        runner = "noderunner.sh"
    runners_template = load_resource(DEV_NODE_DIR, os.path.join("runners", runner))
    runner_path = os.path.join(project_path, runner)
    runner_content = runners_template.format(blocks_path=blocks_folder, deps_path=deps_folder)
    save(runner_path, runner_content)
    os.chmod(runner_path, stat.S_IRWXU)
예제 #8
0
    def test_src_default_accepted(self):
        bii_ignore = BiiIgnore.defaults()
        save(os.path.join(self.folder, 'User/Block/myFile.cpp'), '')

        src_files = walk_bii_folder(self.folder, bii_ignore, self.biiout)
        self.assertEqual(['User/Block/myFile.cpp'], src_files.keys())

        # Check disk
        disk_src_files = set([f.replace('\\', '/') for f in self._get_files()])
        self.assertEqual({'User/Block/myFile.cpp'}, disk_src_files)
예제 #9
0
    def test_src_default_accepted(self):
        bii_ignore = BiiIgnore.defaults()
        save(os.path.join(self.folder, 'User/Block/myFile.cpp'), '')

        src_files = walk_bii_folder(self.folder, bii_ignore, self.biiout)
        self.assertEqual(['User/Block/myFile.cpp'], src_files.keys())

        # Check disk
        disk_src_files = set([f.replace('\\', '/') for f in self._get_files()])
        self.assertEqual({'User/Block/myFile.cpp'},
                         disk_src_files)
예제 #10
0
def init_hive(bii, project_name=None, layout=None):
    """ Initializes an empty project
    """
    user_cache = bii.user_cache
    out = bii.user_io.out

    bii_paths = bii.bii_paths
    if bii_paths.current_dir.startswith(bii_paths.user_bii_home):
        raise BiiException(
            'Cannot create a project inside the user .biicode folder')

    try:
        bii_paths.project_root
        raise ClientException('Cannot create project inside other project')
    except NotInAHiveException:
        pass

    if project_name:
        name = ComplexName(project_name)
        current_dir = os.path.join(bii_paths.current_dir, name)
        bii_paths.current_dir = current_dir
    else:
        current_dir = bii_paths.current_dir
        ComplexName(os.path.basename(current_dir))

    for root, _, _ in os.walk(current_dir):
        if os.path.exists(os.path.join(root, BII_DIR, BII_HIVE_DB)):
            if root == current_dir:
                project_name = os.path.basename(current_dir)
                raise ClientException('Project "%s" already exists' %
                                      project_name)
            raise ClientException(
                'Cannot create project with other project inside:\n%s' % root)

    hive_disk_image = bii.hive_disk_image
    hive_disk_image.initialize()

    try:
        hive = Hive()
        hive_disk_image.hivedb.upsert_hive(hive)
        out.success('Successfully initialized biicode project %s' %
                    (project_name or ""))
    # If an exception is launched, the hive folder is deleted
    except BaseException as e:
        out.error('An error occurred while creating the project %s' % str(e))
        logger.error(traceback.format_exc())
        if project_name and os.path.exists(current_dir):
            hive_disk_image.hivedb.disconnect()
            shutil.rmtree(current_dir)
    else:
        layout_content = user_cache.layout(layout)
        if layout_content:
            save(os.path.join(hive_disk_image.paths.bii, "layout.bii"),
                 layout_content)
예제 #11
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)
예제 #12
0
def create_noderunner(project_path, blocks_folder, deps_folder):
    if platform.system() == 'Windows':
        runner = "noderunner.bat"
    else:
        runner = "noderunner.sh"
    runners_template = load_resource(DEV_NODE_DIR,
                                     os.path.join("runners", runner))
    runner_path = os.path.join(project_path, runner)
    runner_content = runners_template.format(blocks_path=blocks_folder,
                                             deps_path=deps_folder)
    save(runner_path, runner_content)
    os.chmod(runner_path, stat.S_IRWXU)
예제 #13
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)
예제 #14
0
 def migrate(self, *args, **kwargs):
     bii = args[0]
     disk = bii.hive_disk_image
     disk.clean()
     for root, _, _ in os.walk(disk._bii_paths.blocks):
         relative_root = root.replace(disk._bii_paths.blocks + os.sep, "")
         if len(relative_root.split(os.sep)) == 2:
             block = BlockVersion.loads(relative_root.replace(os.sep, "/")).block
             version = bii.biiapi.get_block_info(block).last_version
             if version.time > -1:
                 file_path = os.path.join(root, BII_DIR, "parents.bii")
                 save(file_path, "*%s" % version.to_pretty())
예제 #15
0
파일: migrations.py 프로젝트: toeb/client
 def migrate(self, *args, **kwargs):
     bii = args[0]
     disk = bii.hive_disk_image
     disk.clean()
     for root, _, _ in os.walk(disk._bii_paths.blocks):
         relative_root = root.replace(disk._bii_paths.blocks + os.sep, '')
         if len(relative_root.split(os.sep)) == 2:
             block = BlockVersion.loads(relative_root.replace(os.sep,
                                                              '/')).block
             version = bii.biiapi.get_block_info(block).last_version
             if version.time > -1:
                 file_path = os.path.join(root, BII_DIR, 'parents.bii')
                 save(file_path, '*%s' % version.to_pretty())
예제 #16
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)
예제 #17
0
def init_hive(bii, project_name=None, layout=None):
    """ Initializes an empty project
    """
    user_cache = bii.user_cache
    out = bii.user_io.out

    bii_paths = bii.bii_paths
    if bii_paths.current_dir.startswith(bii_paths.user_bii_home):
        raise BiiException('Cannot create a project inside the user .biicode folder')

    try:
        bii_paths.project_root
        raise ClientException('Cannot create project inside other project')
    except NotInAHiveException:
        pass

    if project_name:
        name = ComplexName(project_name)
        current_dir = os.path.join(bii_paths.current_dir, name)
        bii_paths.current_dir = current_dir
    else:
        current_dir = bii_paths.current_dir
        ComplexName(os.path.basename(current_dir))

    for root, _, _ in os.walk(current_dir):
        if os.path.exists(os.path.join(root, BII_DIR, BII_HIVE_DB)):
            if root == current_dir:
                project_name = os.path.basename(current_dir)
                raise ClientException('Project "%s" already exists' % project_name)
            raise ClientException('Cannot create project with other project inside:\n%s' % root)

    hive_disk_image = bii.hive_disk_image
    hive_disk_image.initialize()

    try:
        hive = Hive()
        hive_disk_image.hivedb.upsert_hive(hive)
        out.success('Successfully initialized biicode project %s' % (project_name or ""))
    # If an exception is launched, the hive folder is deleted
    except BaseException as e:
        out.error('An error occurred while creating the project %s' % str(e))
        logger.error(traceback.format_exc())
        if project_name and os.path.exists(current_dir):
            hive_disk_image.hivedb.disconnect()
            shutil.rmtree(current_dir)
    else:
        layout_content = user_cache.layout(layout)
        if layout_content:
            save(os.path.join(hive_disk_image.paths.bii, "layout.bii"), layout_content)
예제 #18
0
파일: cmaketool.py 프로젝트: toeb/client
 def _create_default_blocks_cmakelists(self, block_targets):
     # create default cmakelists
     project_block = self.bii_paths.root_block
     for block_name, block_target in block_targets.iteritems():
         path_folder = self.bii_paths.deps if block_target.is_dep else self.bii_paths.blocks
         if block_name == project_block:
             cmakelists_path = os.path.join(self.bii_paths.project_root,
                                            "CMakeLists.txt")
         else:
             cmakelists_path = os.path.join(path_folder, block_name,
                                            "CMakeLists.txt")
         cmakelists_path = cmakelists_path.replace('\\',
                                                   '/')  # replace in win32
         if not os.path.exists(cmakelists_path):
             save(cmakelists_path, default_cmake)
예제 #19
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
예제 #20
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)
예제 #21
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
예제 #22
0
파일: eclipse.py 프로젝트: toeb/client
    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)
    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)
예제 #24
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)
예제 #25
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
예제 #26
0
    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)
예제 #27
0
파일: cmake.py 프로젝트: MordodeMaru/client
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)
예제 #28
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)
예제 #29
0
    def test_speed_normalize(self):
        """ this test is only a helper to check performance of normalizing,
        actually the check is very coarse
        """
        folder = tempfile.mkdtemp(suffix='biicode', dir=BII_TEST_FOLDER)
        code = '\r\n'.join(['Hello how are you?' for _ in xrange(4000)])
        path = os.path.join(folder, 'test.cpp')
        save(path, code)
        start_time = time.time()
        count = 30
        for _ in xrange(count):
            with open(path, 'rU') as handle:
                content = handle.read()
        elapsed = time.time() - start_time
        self.assertLess(elapsed, 0.2)
        #print elapsed

        start_time = time.time()
        for _ in xrange(count):
            with open(path, 'rb') as handle:
                content = handle.read()
                content = normalize_text(content)
        elapsed = time.time() - start_time
        self.assertLess(elapsed, 0.2)
예제 #30
0
    def test_speed_normalize(self):
        """ this test is only a helper to check performance of normalizing,
        actually the check is very coarse
        """
        folder = tempfile.mkdtemp(suffix='biicode', dir=BII_TEST_FOLDER)
        code = '\r\n'.join(['Hello how are you?' for _ in xrange(4000)])
        path = os.path.join(folder, 'test.cpp')
        save(path, code)
        start_time = time.time()
        count = 30
        for _ in xrange(count):
            with open(path, 'rU') as handle:
                content = handle.read()
        elapsed = time.time() - start_time
        self.assertLess(elapsed, 0.2)
        #print elapsed

        start_time = time.time()
        for _ in xrange(count):
            with open(path, 'rb') as handle:
                content = handle.read()
                content = normalize_text(content)
        elapsed = time.time() - start_time
        self.assertLess(elapsed, 0.2)
예제 #31
0
    def test_src_default_ignored(self):
        bii_ignore = BiiIgnore.defaults()

        save(os.path.join(self.folder, 'User/Block/.myFile.cpp'), '')
        save(os.path.join(self.folder, 'User/Block/myFile.cpp~'), '')
        save(os.path.join(self.folder, 'User2/Block2/Path/To/HelloWorld.obj'), '')

        src_files = walk_bii_folder(self.folder, bii_ignore, self.biiout)

        src_files = {name: t for name, (t, _) in src_files.iteritems()}
        self.assertEqual({}, src_files)

        # Check disk
        disk_src_files = set([f.replace('\\', '/') for f in self._get_files()])
        self.assertEqual({'User/Block/.myFile.cpp', 'User2/Block2/Path/To/HelloWorld.obj',
                          'User/Block/myFile.cpp~'},
                          disk_src_files)
예제 #32
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
예제 #33
0
    def test_src_default_ignored(self):
        bii_ignore = BiiIgnore.defaults()

        save(os.path.join(self.folder, 'User/Block/.myFile.cpp'), '')
        save(os.path.join(self.folder, 'User/Block/myFile.cpp~'), '')
        save(os.path.join(self.folder, 'User2/Block2/Path/To/HelloWorld.obj'),
             '')

        src_files = walk_bii_folder(self.folder, bii_ignore, self.biiout)

        src_files = {name: t for name, (t, _) in src_files.iteritems()}
        self.assertEqual({}, src_files)

        # Check disk
        disk_src_files = set([f.replace('\\', '/') for f in self._get_files()])
        self.assertEqual(
            {
                'User/Block/.myFile.cpp',
                'User2/Block2/Path/To/HelloWorld.obj', 'User/Block/myFile.cpp~'
            }, disk_src_files)
예제 #34
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
예제 #35
0
    def _test_symlink_files(self, block_folder, block_name, process):
        '''
        Check if walker follows symlinked files
        '''

        file_content = 'palmerita'
        foreign_file_content = 'foreign palmerita'

        # Real block files
        files = [
            'file1.file',
            'subdir1/file2.file',
            'subdir1/subdir2/file3.file',
        ]

        # List of file symlinks (source, link name) (Within the block)
        links = [
            (files[0], 'link1.link'),  # Link belongs to the same directory
            (files[1], 'subdir1/subdir2/link2.link'
             ),  # Link goes upwards the directory hierarchy
            (files[2], 'subdir1/link3.link'
             ),  # Link goes downwards the directory hierarchy
        ]

        # List of file symlinks (source, link name) (Link to external file)
        foreign_links = [('ffile1.ffile', 'flink1.flink'),
                         ('ffile2.ffile', 'subdir1/flink2.flink'),
                         ('ffile3.ffile', 'subdir1/subdir2/flink3.flink')]

        # Create files/links on test folder
        for file_ in [os.path.join(block_folder, x) for x in files]:
            save(file_, file_content)
            assert (os.path.exists(file_))

        for source, dest in [(os.path.join(block_folder, src),
                              os.path.join(block_folder, dest))
                             for src, dest in links]:
            assert (os.path.exists(source))
            os.symlink(source, dest)
            assert (os.path.exists(dest))

        for source, dest in [(os.path.join(block_folder, src),
                              os.path.join(block_folder, dest))
                             for src, dest in foreign_links]:
            save(source, foreign_file_content)
            os.symlink(source, dest)
            assert (os.path.exists(dest))

        # Check results
        collected_files = process()

        def check_file(file_, expected_content):
            key = BlockName(block_name) + file_
            self.assert_(key in collected_files.keys(),
                         '"{}" file not collected'.format(file_))

            content = collected_files[key]
            self.assertEqual(
                content, expected_content, '"{}" file content does not match:'
                ' "{}", expected "{}"'.format(file_, content,
                                              expected_content))

        for file_ in files:
            check_file(file_, file_content)

        for file_, _ in links:
            check_file(file_, file_content)

        for file_, _ in foreign_links:
            check_file(file_, foreign_file_content)
예제 #36
0
    def test_src_custom_ignored(self):
        dest_folder = os.path.join(self.folder, 'User/Block')

        save(os.path.join(dest_folder, 'myFile.cpp'), '')
        save(os.path.join(dest_folder, 'ignore.bii'), '*.kk')
        save(os.path.join(dest_folder, 'subdir1/ignore.bii'), '*.kk1')
        save(os.path.join(dest_folder, 'subdir1/prueba.kk'), '')
        save(os.path.join(dest_folder, 'subdir1/prueba.kk1'), '')
        save(os.path.join(dest_folder, 'subdir1/prueba.kk2'), '')
        save(os.path.join(dest_folder, 'subdir2/ignore.bii'), '*.kk2')
        save(os.path.join(dest_folder, 'subdir2/prueba.kk'), '')
        save(os.path.join(dest_folder, 'subdir2/prueba.kk1'), '')
        save(os.path.join(dest_folder, 'subdir2/prueba.kk2'), '')
        save(os.path.join(dest_folder, 'subdir3/ignore.bii'), 'hello.kk3')
        save(os.path.join(dest_folder, 'subdir3/hello.kk3'), '')
        save(os.path.join(dest_folder, 'subdir4/subdir5/subdir6/ignore.bii'), 'hello.kk5')
        save(os.path.join(dest_folder, 'subdir4/subdir5/subdir6/hello.kk5'), '')

        bii_ignore = BiiIgnore.defaults()
        src_files = walk_bii_folder(self.folder, bii_ignore, self.biiout)

        src_files = src_files.keys()
        self.assertEqual(set(['User/Block/myFile.cpp',
                              'User/Block/ignore.bii',
                              'User/Block/subdir1/ignore.bii',
                              'User/Block/subdir1/prueba.kk2',
                              'User/Block/subdir2/ignore.bii',
                              'User/Block/subdir2/prueba.kk1',
                              'User/Block/subdir3/ignore.bii',
                              'User/Block/subdir4/subdir5/subdir6/ignore.bii']), set(src_files))

        # Check disk
        disk_src_files = set([f.replace('\\', '/') for f in self._get_files()])
        self.assertEqual({'User/Block/myFile.cpp',
                          'User/Block/subdir1/ignore.bii',
                          'User/Block/ignore.bii',
                          'User/Block/subdir2/prueba.kk',
                          'User/Block/subdir2/prueba.kk2',
                          'User/Block/subdir1/prueba.kk2',
                          'User/Block/subdir1/prueba.kk1',
                          'User/Block/subdir2/prueba.kk1',
                          'User/Block/subdir1/prueba.kk',
                          'User/Block/subdir2/ignore.bii',
                          'User/Block/subdir3/ignore.bii',
                          'User/Block/subdir3/hello.kk3',
                          'User/Block/subdir4/subdir5/subdir6/ignore.bii',
                          'User/Block/subdir4/subdir5/subdir6/hello.kk5'},
                          disk_src_files)
예제 #37
0
 def create_new_file(self, block_path, file_name, content=''):
     ''' Create main files with Hello World templates '''
     file_path = os.path.join(block_path, file_name)
     save(file_path, content)  # save method handles exceptions
     msg_succes = 'Success: created {file_name} file in {path}'
     self._biiout.success(msg_succes.format(file_name=file_name, path=block_path))
예제 #38
0
    def test_src_custom_ignored(self):
        dest_folder = os.path.join(self.folder, 'User/Block')

        save(os.path.join(dest_folder, 'myFile.cpp'), '')
        save(os.path.join(dest_folder, 'ignore.bii'), '*.kk')
        save(os.path.join(dest_folder, 'subdir1/ignore.bii'), '*.kk1')
        save(os.path.join(dest_folder, 'subdir1/prueba.kk'), '')
        save(os.path.join(dest_folder, 'subdir1/prueba.kk1'), '')
        save(os.path.join(dest_folder, 'subdir1/prueba.kk2'), '')
        save(os.path.join(dest_folder, 'subdir2/ignore.bii'), '*.kk2')
        save(os.path.join(dest_folder, 'subdir2/prueba.kk'), '')
        save(os.path.join(dest_folder, 'subdir2/prueba.kk1'), '')
        save(os.path.join(dest_folder, 'subdir2/prueba.kk2'), '')
        save(os.path.join(dest_folder, 'subdir3/ignore.bii'), 'hello.kk3')
        save(os.path.join(dest_folder, 'subdir3/hello.kk3'), '')
        save(os.path.join(dest_folder, 'subdir4/subdir5/subdir6/ignore.bii'),
             'hello.kk5')
        save(os.path.join(dest_folder, 'subdir4/subdir5/subdir6/hello.kk5'),
             '')

        bii_ignore = BiiIgnore.defaults()
        src_files = walk_bii_folder(self.folder, bii_ignore, self.biiout)

        src_files = src_files.keys()
        self.assertEqual(
            set([
                'User/Block/myFile.cpp', 'User/Block/ignore.bii',
                'User/Block/subdir1/ignore.bii',
                'User/Block/subdir1/prueba.kk2',
                'User/Block/subdir2/ignore.bii',
                'User/Block/subdir2/prueba.kk1',
                'User/Block/subdir3/ignore.bii',
                'User/Block/subdir4/subdir5/subdir6/ignore.bii'
            ]), set(src_files))

        # Check disk
        disk_src_files = set([f.replace('\\', '/') for f in self._get_files()])
        self.assertEqual(
            {
                'User/Block/myFile.cpp', 'User/Block/subdir1/ignore.bii',
                'User/Block/ignore.bii', 'User/Block/subdir2/prueba.kk',
                'User/Block/subdir2/prueba.kk2',
                'User/Block/subdir1/prueba.kk2',
                'User/Block/subdir1/prueba.kk1',
                'User/Block/subdir2/prueba.kk1',
                'User/Block/subdir1/prueba.kk',
                'User/Block/subdir2/ignore.bii',
                'User/Block/subdir3/ignore.bii',
                'User/Block/subdir3/hello.kk3',
                'User/Block/subdir4/subdir5/subdir6/ignore.bii',
                'User/Block/subdir4/subdir5/subdir6/hello.kk5'
            }, disk_src_files)
예제 #39
0
 def test_bad_location(self):
     bii_ignore = BiiIgnore.defaults()
     save(os.path.join(self.folder, 'User/mybadFile.cpp'), '')
     _ = walk_bii_folder(self.folder, bii_ignore, self.biiout)
     # Check that the system detected misplaced file
     self.assertIn("WARN: User/mybadFile.cpp is misplaced", str(self.biiout))
예제 #40
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))
예제 #41
0
    def __init__(self, root, layout, user_home):
        BiiPaths.__init__(self, root, user_home)

        os.mkdir(os.path.join(root, BII_DIR))  # bii/ folder
        save(os.path.join(root, BII_DIR, BII_HIVE_DB), '')  # fake database file
        save(os.path.join(root, BII_DIR, 'layout.bii'), layout)  # layout file
예제 #42
0
    def _test_symlink_files(self, block_folder, block_name, process):
        '''
        Check if walker follows symlinked files
        '''

        file_content = 'palmerita'
        foreign_file_content = 'foreign palmerita'

        # Real block files
        files = [
            'file1.file',
            'subdir1/file2.file',
            'subdir1/subdir2/file3.file',
        ]

        # List of file symlinks (source, link name) (Within the block)
        links = [
            (files[0], 'link1.link'),  # Link belongs to the same directory
            (files[1], 'subdir1/subdir2/link2.link'),  # Link goes upwards the directory hierarchy
            (files[2], 'subdir1/link3.link'),  # Link goes downwards the directory hierarchy
        ]

        # List of file symlinks (source, link name) (Link to external file)
        foreign_links = [
            ('ffile1.ffile', 'flink1.flink'),
            ('ffile2.ffile', 'subdir1/flink2.flink'),
            ('ffile3.ffile', 'subdir1/subdir2/flink3.flink')
        ]

        # Create files/links on test folder
        for file_ in [os.path.join(block_folder, x) for x in files]:
            save(file_, file_content)
            assert(os.path.exists(file_))

        for source, dest in [(os.path.join(block_folder, src),
                              os.path.join(block_folder, dest))
                             for src, dest in links]:
            assert(os.path.exists(source))
            os.symlink(source, dest)
            assert(os.path.exists(dest))

        for source, dest in [(os.path.join(block_folder, src),
                              os.path.join(block_folder, dest))
                             for src, dest in foreign_links]:
            save(source, foreign_file_content)
            os.symlink(source, dest)
            assert(os.path.exists(dest))

        # Check results
        collected_files = process()

        def check_file(file_, expected_content):
            key = BlockName(block_name) + file_
            self.assert_(key in collected_files.keys(), '"{}" file not collected'.format(file_))

            content = collected_files[key]
            self.assertEqual(content, expected_content,
                             '"{}" file content does not match:'
                             ' "{}", expected "{}"'.format(file_, content, expected_content))

        for file_ in files:
            check_file(file_, file_content)

        for file_, _ in links:
            check_file(file_, file_content)

        for file_, _ in foreign_links:
            check_file(file_, foreign_file_content)
예제 #43
0
 def save(self, model):
     """Saves to file"""
     data = model.serialize()
     data = pickle.dumps(data)
     save(self.config_file_path, data)
예제 #44
0
 def save(self, model):
     """Saves to file"""
     data = model.serialize()
     data = pickle.dumps(data)
     save(self.config_file_path, data)