示例#1
0
 def testCp2(self):
     self._setupTree2()
     self.assertEquals(os.access(path_join(self._tmpd, 'testdir', 'testf'), os.R_OK), False)
     p = Pipeline.parse('cp testf testdir', self._context)
     p.execute_sync()
     self.assertEquals(os.access(path_join(self._tmpd, 'testf'), os.R_OK), True)
     self.assertEquals(os.access(path_join(self._tmpd, 'testdir', 'testf'), os.R_OK), True)
示例#2
0
 def execute(self, context, args, options=[]):
     fs = Filesystem.getInstance()
     if len(args) == 1:
         path = path_join(context.cwd, args[0])
     else:
         path = context.cwd
     if '-a' not in options:
         ignorecheck = True
     else:
         ignorecheck = False 
     for (dirpath, subdirs, fnames) in os.walk(path):
         filtered_dirs = []
         if ignorecheck:
             for i,dpath in enumerate(subdirs):
                 try:
                     dstat = fs.get_file_sync(dpath)
                     if dstat.hidden:
                         filtered_dirs.append(i)
                 except FileStatError as e:
                     continue
             for c,i in enumerate(filtered_dirs):
                 del subdirs[i-c]
         for fname in fnames:
             fpath = path_join(dirpath, fname)                
             fobj = fs.get_file_sync(fpath)
             if ignorecheck and fobj.hidden:
                 continue
             yield fobj
示例#3
0
 def _setupTree2(self):
     self._setupTree1()
     open(path_join(self._tmpd, 'testf2'), 'w').close()
     open(path_join(self._tmpd, 'f3test'), 'w').close()
     open(path_join(self._tmpd, 'otherfile'), 'w').close()
     os.mkdir(path_join(self._tmpd, 'testdir2'))
     open(path_join(self._tmpd, 'testdir2', 'blah'), 'w').close()
示例#4
0
 def _setupTree2(self):
     self._setupTree1()
     open(path_join(self._tmpd, 'testf2'), 'w').close()
     open(path_join(self._tmpd, 'f3test'), 'w').close()
     open(path_join(self._tmpd, 'otherfile'), 'w').close()
     os.mkdir(path_join(self._tmpd, 'testdir2'))
     open(path_join(self._tmpd, 'testdir2', 'blah'), 'w').close()
示例#5
0
 def testRm4(self):
     self._setupTree2()
     p = Pipeline.parse('rm %s %s' % (path_join(self._tmpd, 'f3test'), path_join(self._tmpd, 'otherfile')),
                        self._context)
     p.execute_sync()
     self.assertEquals(os.access(path_join(self._tmpd, 'testf'), os.R_OK), True)
     self.assertEquals(os.access(path_join(self._tmpd, 'f3test'), os.R_OK), False)
     self.assertEquals(os.access(path_join(self._tmpd, 'otherfile'), os.R_OK), False)
示例#6
0
 def testRm8(self):
     self._setupTree2()
     self.assertEquals(os.access(path_join(self._tmpd, 'testf'), os.R_OK), True)
     self.assertEquals(os.access(path_join(self._tmpd, 'f3test'), os.R_OK), True)               
     p = Pipeline.parse('ls testf f3test | rm --unlink', self._context)
     p.execute_sync()
     self.assertEquals(os.access(path_join(self._tmpd, 'testf'), os.R_OK), False)
     self.assertEquals(os.access(path_join(self._tmpd, 'f3test'), os.R_OK), False)
示例#7
0
 def testRm6(self):
     self._setupTree1()
     self.assertEqual(
         os.access(path_join(self._tmpd, 'dir with spaces'), os.R_OK), True)
     p = Pipeline.parse("rm 'dir with spaces'", self._context)
     p.execute_sync()
     self.assertEqual(
         os.access(path_join(self._tmpd, 'dir with spaces'), os.R_OK),
         False)
示例#8
0
 def testRedir1(self):
     self._setupTree2()
     p = Pipeline.parse("ls testdir2 | prop path > outtest.txt", self._context)
     p.execute_sync()
     outpath = path_join(self._tmpd, 'outtest.txt')
     self.assertEquals(os.access(outpath, os.R_OK), True)
     lines = list(open(outpath))
     self.assertEquals(len(lines), 1)
     self.assertEquals(lines[0], path_join(self._tmpd, 'testdir2', 'blah'))
示例#9
0
 def testCwd8(self):
     self._setupTree1()
     result = self.cc.sync_complete(self.vc, './test', self._tmpd)
     self.assertEqual(len(result.results), 2)
     self.assertEqual(result.common_prefix, None)      
     self.assertEqual(result.results[0].target.path, path_join(self._tmpd, '.', 'testdir'))
     self.assertEqual(result.results[0].suffix, 'dir/')
     self.assertEqual(result.results[1].target.path, path_join(self._tmpd, '.', self._test_exe))
     self.assertEqual(result.results[1].suffix, self._test_exe[4:])
示例#10
0
 def testRm5(self):
     self._setupTree1()
     p = Pipeline.parse('rm testf', self._context)
     p.execute_sync()
     self.assertEquals(os.access(path_join(self._tmpd, 'testf'), os.R_OK), False)
     open(path_join(self._tmpd, 'testf'), 'w').close()
     self.assertEquals(os.access(path_join(self._tmpd, 'testf'), os.R_OK), True)
     p = Pipeline.parse('rm testf', self._context)
     p.execute_sync()
     self.assertEquals(os.access(path_join(self._tmpd, 'testf'), os.R_OK), False)
示例#11
0
 def testCp5(self):
     self._setupTree2()
     p = Pipeline.parse('cp testf \'dir with spaces\' testdir2',
                        self._context)
     p.execute_sync()
     self.assertEqual(
         os.access(path_join(self._tmpd, 'testdir2', 'testf'), os.R_OK),
         True)
     self.assertEqual(
         os.access(path_join(self._tmpd, 'testdir2', 'dir with spaces'),
                   os.R_OK), True)
示例#12
0
 def _setupTree1(self):
     self._tmpd = tempfile.mkdtemp(prefix='hotwiretest')
     os.mkdir(path_join(self._tmpd, 'testdir'))
     if is_unix():
         self._test_exe = 'testf'
     elif is_windows():
         self._test_exe = 'testf.exe'
     self._test_exe_path = path_join(self._tmpd, self._test_exe)
     open(self._test_exe_path, 'w').close()
     if is_unix():
         os.chmod(self._test_exe_path, 744)            
     os.mkdir(path_join(self._tmpd, 'dir with spaces'))
示例#13
0
 def testRedir1(self):
     self._setupTree2()
     outpath = path_join(self._tmpd, 'redirtest.txt')
     f= open(outpath, 'w')
     testdata = 'hello world\nhow are you?\n'
     f.write(testdata)
     f.close()
     p = Pipeline.parse("sys cat < redirtest.txt > same_redirtest.txt", self._context)
     p.execute_sync()
     newoutpath = path_join(self._tmpd, 'same_redirtest.txt')
     self.assertEqual(os.access(newoutpath, os.R_OK), True)
     same_testdata = open(newoutpath).read()
     self.assertEqual(same_testdata, testdata)
示例#14
0
 def testRedir1(self):
     self._setupTree2()
     outpath = path_join(self._tmpd, 'redirtest.txt')
     f = open(outpath, 'w')
     testdata = 'hello world\nhow are you?\n'
     f.write(testdata)
     f.close()
     p = Pipeline.parse("sys cat < redirtest.txt > same_redirtest.txt",
                        self._context)
     p.execute_sync()
     newoutpath = path_join(self._tmpd, 'same_redirtest.txt')
     self.assertEqual(os.access(newoutpath, os.R_OK), True)
     same_testdata = open(newoutpath).read()
     self.assertEqual(same_testdata, testdata)
示例#15
0
 def testCwd5(self):
     self._setupTree2()
     result = self.cc.sync_complete(self.pc, 'testdir2/m', self._tmpd)
     self.assertEqual(len(result.results), 2)
     self.assertEqual(result.results[0].target.path, path_join(self._tmpd, 'testdir2', 'moo'))           
     self.assertEqual(result.results[0].suffix, 'oo')
     self.assertEqual(result.results[1].suffix, 'oodir/')
示例#16
0
def head(context, *files):
    _("""Return a subset of items from start of input stream.""")
    count = 10
    countidx = -1
    # Create a copy so we can delete from it safely
    files = list(files)
    for i,arg in enumerate(files):
        if arg.startswith('-'):
            count = int(arg[1:])
            countidx = i
            break
    if countidx >= 0:
        del files[countidx]
    if context.input is not None:
        for i,value in enumerate(context.input):
            if i >= count:
                break
            yield value
    for fpath in files:
        fpath = path_join(context.cwd, fpath)
        f = None
        f = open_text_file(fpath)
        for i,line in enumerate(f):
            if i>= count:
                break
            yield line
        f.close()
示例#17
0
 def testRm2(self):
     self._setupTree1()
     testf_path = path_join(self._tmpd, 'testf') 
     self.assertEquals(os.access(testf_path, os.R_OK), True)
     p = Pipeline.parse('rm %s' % (testf_path,), self._context)
     p.execute_sync()
     self.assertEquals(os.access(testf_path, os.R_OK), False)
示例#18
0
 def testCp4(self):
     self._setupTree2()
     p = Pipeline.parse('cp testdir2 testdir3', self._context)
     p.execute_sync()
     self.assertEqual(
         os.access(path_join(self._tmpd, 'testdir3', 'blah'), os.R_OK),
         True)
示例#19
0
 def testCwd7(self):
     self._setupTree2()
     result = self.cc.sync_complete(self.pc, './f3', self._tmpd)
     self.assertEqual(len(result.results), 1)
     self.assertEqual(result.common_prefix, None) 
     self.assertEqual(result.results[0].target.path, path_join(self._tmpd, '.', 'f3test'))
     self.assertEqual(result.results[0].suffix, 'test')
示例#20
0
 def testCwd6(self):
     self._setupTree1()
     result = self.cc.sync_complete(self.pc, './testd', self._tmpd)
     self.assertEquals(len(result.results), 1)
     self.assertEquals(result.common_prefix, None)        
     self.assertEquals(result.results[0].target.path, path_join(self._tmpd, '.', 'testdir'))
     self.assertEquals(result.results[0].suffix, 'ir/')
示例#21
0
 def testCd(self):
     self._setupTree1()
     oldwd = self._context.get_cwd()
     p = Pipeline.parse('cd testdir', self._context)
     p.execute_sync()
     self.assertEqual(self._context.get_cwd(),
                      path_abs(path_join(oldwd, 'testdir')))
示例#22
0
def head(context, *files):
    _("""Return a subset of items from start of input stream.""")
    count = 10
    countidx = -1
    # Create a copy so we can delete from it safely
    files = list(files)
    for i, arg in enumerate(files):
        if arg.startswith('-'):
            count = int(arg[1:])
            countidx = i
            break
    if countidx >= 0:
        del files[countidx]
    if context.input is not None:
        for i, value in enumerate(context.input):
            if i >= count:
                break
            yield value
    for fpath in files:
        fpath = path_join(context.cwd, fpath)
        f = None
        f = open_text_file(fpath)
        for i, line in enumerate(f):
            if i >= count:
                break
            yield line
        f.close()
示例#23
0
 def testRm2(self):
     self._setupTree1()
     testf_path = path_join(self._tmpd, 'testf')
     self.assertEqual(os.access(testf_path, os.R_OK), True)
     p = Pipeline.parse('rm %s' % (testf_path, ), self._context)
     p.execute_sync()
     self.assertEqual(os.access(testf_path, os.R_OK), False)
示例#24
0
 def testWrite1(self):
     self._setupTree1()
     p = Pipeline.parse("ls | py-map 'it.path+\"\\n\"' | write outtest.txt", self._context)
     p.execute_sync()
     outpath = path_join(self._tmpd, 'outtest.txt')
     self.assertEqual(os.access(outpath, os.R_OK), True)
     lines = list(open(outpath))
     self.assertEqual(len(lines), 3)
示例#25
0
 def testLs2(self):
     self._setupTree1()
     hidden = path_join(self._tmpd, '.nosee')
     open(hidden, 'w').close()
     p = Pipeline.parse("ls -a", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEqual(len(results), 4)
示例#26
0
 def testLsQuoted(self):
     self._setupTree1()
     hidden = path_join(self._tmpd, "foo'bar")
     open(hidden, 'w').close()
     p = Pipeline.parse("ls \"foo'bar\"", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEquals(len(results), 1)
示例#27
0
 def testLs2(self):
     self._setupTree1()
     hidden = path_join(self._tmpd, '.nosee')
     open(hidden, 'w').close()
     p = Pipeline.parse("ls -a", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEqual(len(results), 4)
示例#28
0
 def testCdQuoted(self):
     self._setupTree1()
     p = path_join(self._tmpd, "foo'bar")
     os.mkdir(p)
     p = Pipeline.parse("cd \"foo'bar\"", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEquals(len(results), 0)
示例#29
0
 def testCdQuoted(self):
     self._setupTree1()
     p = path_join(self._tmpd, "foo'bar")
     os.mkdir(p)
     p = Pipeline.parse("cd \"foo'bar\"", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEqual(len(results), 0)
示例#30
0
 def testSpaces1(self):
     self._setupTree1()
     dpath = path_join(self._tmpd, 'dir with spaces')   
     result = self.cc.sync_complete(self.pc, 'di', self._tmpd)
     self.assertEqual(len(result.results), 1)
     self.assertEqual(result.common_prefix, None)
     self.assertEqual(result.results[0].target.path, dpath)
     self.assertEqual(result.results[0].suffix, r'r\ with\ spaces/')        
示例#31
0
 def testLsQuoted(self):
     self._setupTree1()
     hidden = path_join(self._tmpd, "foo'bar")
     open(hidden, 'w').close()
     p = Pipeline.parse("ls \"foo'bar\"", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEqual(len(results), 1)
示例#32
0
 def testNewlineAndWrite1(self):
     self._setupTree1()
     p = Pipeline.parse("ls|prop path|newline|write outtest.txt", self._context)
     p.execute_sync()
     outpath = path_join(self._tmpd, 'outtest.txt')
     self.assertEquals(os.access(outpath, os.R_OK), True)
     lines = list(open(outpath))
     self.assertEquals(len(lines), 3)
示例#33
0
 def testSafechar2(self):
     self._setupTree1()
     bpath = path_join(self._tmpd, 'bar+')
     os.mkdir(bpath)    
     result = self.cc.sync_complete(self.pc, 'ba', self._tmpd)
     self.assertEqual(len(result.results), 1)
     self.assertEqual(result.common_prefix, None)
     self.assertEqual(result.results[0].target.path, bpath)
     self.assertEqual(result.results[0].suffix, 'r+/')
示例#34
0
 def testWrite1(self):
     self._setupTree1()
     p = Pipeline.parse("ls | py-map 'it.path+\"\\n\"' | write outtest.txt",
                        self._context)
     p.execute_sync()
     outpath = path_join(self._tmpd, 'outtest.txt')
     self.assertEqual(os.access(outpath, os.R_OK), True)
     lines = list(open(outpath))
     self.assertEqual(len(lines), 3)
示例#35
0
 def testRm9(self):
     self._setupTree1()
     t = path_join(self._tmpd, '--frob')
     f = open(t, 'w')
     f.write('hi')
     f.close()
     self.assertEqual(os.access(t, os.R_OK), True)
     p = Pipeline.parse('rm --unlink -- --frob', self._context)
     p.execute_sync()
     self.assertEqual(os.access(t, os.R_OK), False)
示例#36
0
 def testRm9(self):
     self._setupTree1()
     t = path_join(self._tmpd, '--frob')
     f = open(t, 'w')
     f.write('hi')
     f.close()
     self.assertEquals(os.access(t, os.R_OK), True)        
     p = Pipeline.parse('rm --unlink -- --frob', self._context)
     p.execute_sync()
     self.assertEquals(os.access(t, os.R_OK), False)
示例#37
0
 def testSafechar1(self):
     self._setupTree1()
     bpath = path_join(self._tmpd, 'bar_foo')
     f=open(bpath, 'w')
     f.write('hi')
     f.close()              
     result = self.cc.sync_complete(self.pc, 'ba', self._tmpd)
     self.assertEqual(len(result.results), 1)
     self.assertEqual(result.common_prefix, None)
     self.assertEqual(result.results[0].target.path, bpath)
     self.assertEqual(result.results[0].suffix, 'r_foo')
示例#38
0
 def testCat1(self):
     self._setupTree2()
     outpath = path_join(self._tmpd, 'cattest.txt')
     f = open(outpath, 'wb')
     f.write('hello world\n')
     f.close()
     p = Pipeline.parse("cat cattest.txt", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0], 'hello world\n')
示例#39
0
 def testCat1(self):
     self._setupTree2()
     outpath = path_join(self._tmpd, 'cattest.txt')
     f= open(outpath, 'wb')
     f.write('hello world\n')       
     f.close()
     p = Pipeline.parse("cat cattest.txt", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEquals(len(results), 1)
     self.assertEquals(results[0], 'hello world\n')    
示例#40
0
 def testCwd9(self):
     self._setupTree1()
     dotpath = path_join(self._tmpd, '.foo')
     f=open(dotpath, 'w')
     f.write('hi')
     f.close()
     dotpath = path_join(self._tmpd, '.bar')
     f=open(dotpath, 'w')
     f.write('there')
     f.close()                
     result = self.cc.sync_complete(self.pc, '', self._tmpd)
     self.assertEqual(len(result.results), 5)
     self.assertEqual(result.common_prefix, None)
     self.assertEqual(result.results[0].target.path, path_join(self._tmpd, '.bar'))
     self.assertEqual(result.results[0].suffix, '.bar')
     foo_index=2
     if is_windows():
         foo_index = 1
     self.assertEqual(result.results[foo_index].target.path, path_join(self._tmpd, '.foo'))
     self.assertEqual(result.results[foo_index].suffix, '.foo')
示例#41
0
 def testLs3(self):
     self._setupTree2()
     bglobpath = path_join(self._tmpd, 'testdir2', 'b*')
     f = open(bglobpath, 'w')
     f.write('hi')
     f.close()
     p = Pipeline.parse("ls 'testdir2/b*'", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].path, bglobpath)
示例#42
0
 def testLs3(self):
     self._setupTree2()
     bglobpath = path_join(self._tmpd, 'testdir2', 'b*') 
     f = open(bglobpath, 'w')
     f.write('hi')
     f.close()
     p = Pipeline.parse("ls 'testdir2/b*'", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].path, bglobpath)
示例#43
0
 def testCdQuoted2(self):
     if is_windows():
         # The double quote " apparently is not valid in file names on NTFS.  
         # Just don't run this test then.
         return
     self._setupTree1()
     p = path_join(self._tmpd, "foo\"bar")
     os.mkdir(p)
     p = Pipeline.parse("cd 'foo\"bar'", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEquals(len(results), 0)
示例#44
0
 def testRedir2(self):
     self._setupTree2()
     outpath = path_join(self._tmpd, 'sectest.txt')
     f= open(outpath, 'wb')
     f.write('hello world\n')
     f.write('sha test\n')        
     f.close()
     p = Pipeline.parse("sechash < sectest.txt", self._context)
     p.execute_sync()
     results = list(p.get_output())
     self.assertEquals(len(results), 2)
     self.assertEquals(results[0], '22596363b3de40b06f981fb85d82312e8c0ed511')
     self.assertEquals(results[1], '84b5d4093c8ffaf2eca0feaf014a53b9f41d28ed')
示例#45
0
 def _setupTree2(self):
     self._setupTree1()
     if is_unix(): 
         self._test_exe2_path = path_join(self._tmpd, 'testf2')
         open(self._test_exe2_path, 'w').close()
         os.chmod(self._test_exe2_path, 744)
     elif is_windows():
         self._test_exe2_path = path_join(self._tmpd, 'testf2.exe')
         open(self._test_exe2_path, 'w').close()
     open(path_join(self._tmpd, 'f3test'), 'w').close()
     open(path_join(self._tmpd, 'otherfile'), 'w').close()
     os.mkdir(path_join(self._tmpd, 'testdir2'))
     open(path_join(self._tmpd, 'testdir2', 'blah'), 'w').close()
     open(path_join(self._tmpd, 'testdir2', 'moo'), 'w').close()
     os.mkdir(path_join(self._tmpd, 'testdir2', 'moodir'))