예제 #1
0
 def test_move_files(self):
     tmp_dir = self.make_temp_dir()
     src_dir = path.join(tmp_dir, 'src')
     dst_dir = path.join(tmp_dir, 'dst')
     file_util.mkdir(dst_dir)
     temp_content.write_items([
         'file foo.txt "This is foo.txt\n" 644',
         'file bar.txt "This is bar.txt\n" 644',
         'file sub1/sub2/baz.txt "This is baz.txt\n" 644',
         'file yyy/zzz/vvv.txt "This is vvv.txt\n" 644',
         'file .hidden "this is .hidden\n" 644',
         'file script.sh "#!/bin/bash\necho script.sh\nexit 0\n" 755',
         'file .hushlogin "" 644',
     ], src_dir)
     expected = [
         self.native_filename('.hidden'),
         self.native_filename('.hushlogin'),
         self.native_filename('bar.txt'),
         self.native_filename('foo.txt'),
         self.native_filename('script.sh'),
         self.native_filename('sub1/sub2/baz.txt'),
         self.native_filename('yyy/zzz/vvv.txt'),
     ]
     self.assertEqual(expected, file_find.find(src_dir, relative=True))
     file_copy.move_files(src_dir, dst_dir)
     self.assertEqual(expected, file_find.find(dst_dir, relative=True))
     self.assertEqual([], file_find.find(src_dir, relative=True))
예제 #2
0
 def test_foo(self):
   env = {
     'SOMETHINGIMADEUP': 'GOOD',
     'PATH': '/bin:/usr/bin:/my/path:/sbin'
   }
   with env_override(env = env) as tmp_env:
     tmp_dir = self.make_temp_dir()
     temp_content.write_items([
       'file 1.sh "export PATH=/bin:/usr/bin:/sbin\n" 644',
       'file 2.sh "export BAR=orange\n" 644',
       'file 3.sh "export PATH=/a/bin:$PATH\nexport PATH=/b/bin:$PATH\n" 644',
       'file 4.sh "export FOO=kiwi\n" 644',
       'file 5.sh "export PATH=$PATH:/x/bin\nPATH=$PATH:/y/bin\n" 644',
       'file 6.sh "unset SOMETHINGIMADEUP\n" 644',
     ], tmp_dir)
     ed = env_dir(tmp_dir)
     self.assertEqual( [ '1.sh', '2.sh', '3.sh', '4.sh', '5.sh', '6.sh' ], ed.files )
     self.assertEqual( [
       ( 'BAR', 'orange', action.SET ),
       ( 'FOO', 'kiwi', action.SET ),
       ( 'PATH', '/a/bin', action.PATH_PREPEND ),
       ( 'PATH', '/b/bin', action.PATH_PREPEND ),
       ( 'PATH', '/my/path', action.PATH_REMOVE ),
       ( 'PATH', '/x/bin', action.PATH_APPEND ),
       ( 'PATH', '/y/bin', action.PATH_APPEND ),
       ( 'SOMETHINGIMADEUP', None, action.UNSET ),
     ], ed.instructions(tmp_env.to_dict()) )
예제 #3
0
 def _test_resolve(self,
                   func,
                   items,
                   files,
                   recursive = True,
                   limit = None,
                   sort_order = None,
                   sort_reverse = False,
                   match_patterns = None,
                   match_type = None,
                   match_basename = True,
                   match_function = None,
                   match_re = None,
                   ignore_files = None):
   tmp_dir = self.make_temp_dir()
   temp_content.write_items(items, tmp_dir)
   files = [ f.replace('${tmp_dir}', tmp_dir) for f in files ]
   options = file_resolver_options(recursive = recursive,
                                   limit = limit,
                                   sort_order = sort_order,
                                   sort_reverse = sort_reverse,
                                   match_patterns = match_patterns,
                                   match_type = match_type,
                                   match_basename = match_basename,
                                   match_function = match_function,
                                   match_re = match_re,
                                   ignore_files = ignore_files)
   result = func(files, options = options)
   return os.linesep.join([ self._fix_one_resolved_file(f, tmp_dir) for f in result ])
예제 #4
0
파일: git_repo.py 프로젝트: reconstruir/bes
 def write_temp_content(self, items, commit = False, commit_message = None):
   commit_message = commit_message or 'add temp content'
   temp_content.write_items(items, self.root)
   if commit:
     if self.has_changes():
       raise git_error('You need a clean tree with no changes to add temp content.')
     self.add('.')
     self.commit(commit_message, '.')
예제 #5
0
 def _make_temp_content(self):
   tmp_dir = self.make_temp_dir()
   items = [
     'file cheese/soft/brie.cheese "this is brie" 644',
     'file cheese/hard/cheddar.cheese "this is cheddar" 644',
     'file fruit/kiwi.fruit "this is kiwi" 644',
     'file fruit/orange.fruit "this is orange" 644',
   ]
   temp_content.write_items(items, tmp_dir)
   return tmp_dir
예제 #6
0
 def test_write_items(self):
   tmp_dir = self.make_temp_dir()
   I.write_items([
     'file a/b/c/foo.txt "foo content" 755',
     'file d/e/bar.txt "bar content" 644',
     'dir  baz     ""            700',
   ], tmp_dir)
   self.assertTrue( path.isfile(path.join(tmp_dir, self.native_filename('a/b/c/foo.txt'))) )
   self.assertTrue( path.isfile(path.join(tmp_dir, self.native_filename('d/e/bar.txt'))) )
   self.assertTrue( path.isdir(path.join(tmp_dir, self.native_filename('baz'))) )
예제 #7
0
 def _make_temp_content(clazz, items):
     tmp_dir = temp_file.make_temp_dir()
     temp_content.write_items(items, tmp_dir)
     return tmp_dir
예제 #8
0
 def _make_temp_env_dir(self, items, files = None):
   tmp_dir = self.make_temp_dir()
   temp_content.write_items(items, tmp_dir)
   return env_dir(tmp_dir, files = files)
예제 #9
0
 def write_temp_content(self, items):
   temp_content.write_items(items, self.root_dir)
예제 #10
0
 def _make_temp_content(clazz, items):
     r = git_temp_repo(remote=True, debug=clazz.DEBUG)
     temp_content.write_items(items, r.root)
     r.add('.')
     r.commit('add', '.')
     return r