コード例 #1
0
ファイル: filelist.py プロジェクト: lakshmipriyap/cobalt
def _ResolveSymLink(link_file):
    target_path = port_symlink.ReadSymLink(link_file)
    if os.path.exists(target_path):  # Absolute path
        return target_path
    else:
        return os.path.join(link_file,
                            target_path)  # Relative path from link_file.
コード例 #2
0
 def testExtractTo(self):
     flist = filelist.FileList()
     tf = filelist_test.TempFileSystem()
     tf.Clear()
     tf.Make()
     flist.AddFile(tf.root_in_tmp, tf.test_txt)
     flist.AddSymLink(tf.root_in_tmp, tf.sym_dir)
     bundle_zip = os.path.join(tf.root_tmp, 'bundle.zip')
     car = cobalt_archive.CobaltArchive(bundle_zip)
     car.MakeArchive(platform_name='fake',
                     platform_sdk_version='fake_sdk',
                     config='devel',
                     file_list=flist)
     out_dir = os.path.join(tf.root_tmp, 'out')
     car.ExtractTo(out_dir)
     out_from_dir = os.path.join(out_dir, 'from_dir')
     out_from_dir_lnk = os.path.join(out_dir, 'from_dir_lnk')
     self.assertEqual(filelist.GetFileType(out_from_dir),
                      filelist.TYPE_DIRECTORY)
     self.assertEqual(filelist.GetFileType(out_from_dir_lnk),
                      filelist.TYPE_SYMLINK_DIR)
     resolved_from_link_path = os.path.join(
         out_dir, port_symlink.ReadSymLink(out_from_dir_lnk))
     self.assertEqual(os.path.abspath(out_from_dir),
                      os.path.abspath(resolved_from_link_path))
コード例 #3
0
def _ResolveSymLink(link_file):
  """Returns the absolute path of the resolved link. This path should exist."""
  target_path = port_symlink.ReadSymLink(link_file)
  if os.path.isabs(target_path):  # Absolute path
    assert os.path.exists(target_path), (
        'Path {} does not exist.'.format(target_path))
    return target_path
  else:  # Relative path from link_file.
    abs_path = os.path.normpath(
        os.path.join(os.path.dirname(link_file), target_path))
    assert os.path.exists(abs_path), (
        'Path {} does not exist (link file: {}, target_path: {})'.format(
            abs_path, link_file, target_path))
    return abs_path
コード例 #4
0
ファイル: filelist_test.py プロジェクト: lakshmipriyap/cobalt
 def testAddRelativeSymlink(self):
     """Tests the that adding a relative symlink works as expected."""
     tf = TempFileSystem()
     tf.Make()
     flist = filelist.FileList()
     in2 = os.path.join(tf.root_in_tmp, 'in2')
     target_path = os.path.relpath(tf.from_dir, in2)
     # Sanity check that target_path is relative.
     self.assertIn('..', target_path)
     port_symlink.MakeSymLink(target_path, in2)
     self.assertTrue(port_symlink.IsSymLink(in2))
     read_back_target_path = port_symlink.ReadSymLink(in2)
     self.assertIn('..', read_back_target_path)
     flist.AddFile(tf.root_tmp, in2)
     flist.Print()
     self.assertTrue(flist.symlink_dir_list)
     symlink_entry = flist.symlink_dir_list[0][1:]
     expected = [os.path.join('in', 'in2'), os.path.join('in', 'from_dir')]
     self.assertEqual(expected, symlink_entry)
コード例 #5
0
 def testAddRelativeSymlink(self):
     """Tests that adding a relative symlink works as expected."""
     tf = TempFileSystem()
     tf.Make()
     flist = filelist.FileList()
     in2 = os.path.join(tf.root_in_tmp, 'subdir', 'in2')
     target_path = os.path.relpath(tf.from_dir, os.path.dirname(in2))
     # Sanity check that target_path is relative.
     self.assertEqual(target_path, os.path.join('..', 'from_dir'))
     # Create the link and check that it points to the correct folder.
     port_symlink.MakeSymLink(target_path, in2)
     self.assertTrue(port_symlink.IsSymLink(in2))
     self.assertEqual(port_symlink.ReadSymLink(in2), target_path)
     self.assertEqual(os.listdir(in2), ['test.txt'])
     # Add the symlink to flist and check its content.
     flist.AddFile(tf.root_tmp, in2)
     flist.Print()
     self.assertTrue(flist.symlink_dir_list)
     expected = [
         tf.root_tmp,
         os.path.join('in', 'subdir', 'in2'),
         os.path.join('in', 'from_dir')
     ]
     self.assertEqual(flist.symlink_dir_list[0], expected)
コード例 #6
0
def ReadSymLink(*args, **kwargs):
  return port_symlink.ReadSymLink(*args, **kwargs)