def GetFileType(f): if not os.path.exists(f): return TYPE_NONE elif port_symlink.IsSymLink(f): return TYPE_SYMLINK_DIR elif os.path.isdir(f): return TYPE_DIRECTORY else: assert os.path.isfile(f) return TYPE_FILE
def AddAllFilesInPath(self, root_dir, sub_path): """Starting at the root path, the sub_paths are searched for files.""" all_files = [] all_symlinks = [] if os.path.isfile(sub_path): self.AddFile(root_dir, sub_path) elif not os.path.isdir(sub_path): raise IOError('Expected root directory to exist: %s' % sub_path) for root, dirs, files in port_symlink.OsWalk(sub_path): for f in files: full_path = os.path.abspath(os.path.join(root, f)) all_files.append(full_path) for dir_name in dirs: full_path = os.path.abspath(os.path.join(root, dir_name)) if port_symlink.IsSymLink(full_path): all_symlinks.append(full_path) for f in all_files + all_symlinks: self.AddFile(root_dir, f)
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)
def _FindPossibleDeployPaths(build_root): """Searches for folders that are likely required for archiving.""" out = [] # Ultimately, this function should not be needed as each platform should # implement GetDeployPathPatterns(). This is stop-gap for platforms that do # not have GetDeployPathPatterns() implemented yet. root_paths = os.listdir(build_root) for p in root_paths: if p in ('gen', 'gypfiles', 'gyp-win-tool', 'obj', 'obj.host'): continue if p.endswith('.pdb'): continue # Skip pdb files for size (only applies to Windows). p = os.path.join(build_root, p) if os.path.isfile(p): out.append(p) continue if port_symlink.IsSymLink(p): continue out.append(os.path.normpath(p)) return out
def AddAllFilesInPath(self, root_dir, sub_path): """Starting at the root path, the sub_paths are searched for files.""" all_files = [] all_symlinks = [] if os.path.isfile(sub_path): self.AddFile(root_dir, sub_path) elif not os.path.isdir(sub_path): raise IOError('Expected root directory to exist: %s' % sub_path) cwd = os.getcwd() for root, dirs, files in port_symlink.OsWalk(sub_path): # Do not use os.path.abspath as it does not work on Win for long paths. if not os.path.isabs(root): root = os.path.join(cwd, root) for f in files: full_path = os.path.join(root, f) all_files.append(full_path) for dir_name in dirs: full_path = os.path.join(root, dir_name) if port_symlink.IsSymLink(full_path): all_symlinks.append(full_path) for f in all_files + all_symlinks: self.AddFile(root_dir, f)
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)
def AddFile(self, root_path, file_path): if port_symlink.IsSymLink(file_path): self.AddSymLink(root_path, file_path) else: archive_name = _OsGetRelpath(file_path, root_path) self.file_list.append([file_path, archive_name])
def IsSymLink(*args, **kwargs): return port_symlink.IsSymLink(*args, **kwargs)