Example #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)
Example #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
Example #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()
Example #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()
Example #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)
Example #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)
Example #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)
Example #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'))
Example #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:])
Example #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)
Example #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)
Example #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'))
 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)
 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)
Example #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/')
Example #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()
Example #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)
Example #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)
Example #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')
Example #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/')
Example #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')))
Example #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()
Example #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)
Example #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)
 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)
Example #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)
 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)
Example #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)
Example #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)
Example #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/')        
Example #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)
Example #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)
Example #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+/')
Example #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)
Example #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)
Example #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)
Example #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')
Example #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')
Example #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')    
Example #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')
 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)
 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)
Example #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)
Example #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')
Example #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'))