• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sh.ls函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sh.ls函数的典型用法代码示例。如果您正苦于以下问题:Python ls函数的具体用法?Python ls怎么用?Python ls使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ls函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: up

    def up(self):
        remote_dir = self.remote_dir
        if not os.path.exists(remote_dir):
            os.mkdir(remote_dir)

        tries = 5
        while tries > 0:
            self.mount(remote_dir)
            sleep(1)

            try:
                sh.ls(remote_dir)
            except sh.ErrorReturnCode:
                pstor.umount(remote_dir)
            else:
                break

            tries -= 1
        else:
            raise exceptions.PstorException("Can't ls in mounted webdav directory")

        remote_dir = os.path.join(self.remote_dir, 'pstor/')

        if not os.path.exists(remote_dir):
            os.mkdir(remote_dir)
        #TODO: Check if not rewrites files (e.g. existing repo in new repo)
        sh.rsync(remote_dir, '.pstor/encrypted', recursive=True)
开发者ID:rrader,项目名称:pstor,代码行数:27,代码来源:webdav.py


示例2: add_all_files

    def add_all_files(self):
        SUFFIXES = {'_dat.zip',
                    '_metadata.xml',
                    'README.md',
                    'CONTRIBUTING.md',
                    'LICENSE.md',
                    '.adoc'
                    }
        with CdContext(self.directory):
            sh.git.init('.')

            logging.debug("Files to add: " + str(sh.ls()))

            # NOTE: repo.untracked_files is unreliable with CdContext
            # using sh.ls() instead, this doesn't recognize .gitignore
            for _file in sh.ls('-1'):
                # TODO: This attempts to add existing files a second time
                _file = _file.rstrip('\n')
                for suffix in SUFFIXES:
                    if _file.endswith(suffix):
                        logging.info("Adding file: " + _file)
                        self.add_file(_file)
                        break
                else:
                    logging.debug('Skipping ' + _file)
开发者ID:JohannGillium,项目名称:git-lit,代码行数:25,代码来源:local.py


示例3: prebuild_arch

 def prebuild_arch(self, arch):
     if not self.is_patched(arch):
         super(ReportLabRecipe, self).prebuild_arch(arch)
         self.apply_patch('patches/fix-setup.patch', arch.arch)
         recipe_dir = self.get_build_dir(arch.arch)
         shprint(sh.touch, os.path.join(recipe_dir, '.patched'))
         ft = self.get_recipe('freetype', self.ctx)
         ft_dir = ft.get_build_dir(arch.arch)
         ft_lib_dir = os.environ.get('_FT_LIB_', os.path.join(ft_dir, 'objs', '.libs'))
         ft_inc_dir = os.environ.get('_FT_INC_', os.path.join(ft_dir, 'include'))
         tmp_dir = os.path.normpath(os.path.join(recipe_dir, "..", "..", "tmp"))
         info('reportlab recipe: recipe_dir={}'.format(recipe_dir))
         info('reportlab recipe: tmp_dir={}'.format(tmp_dir))
         info('reportlab recipe: ft_dir={}'.format(ft_dir))
         info('reportlab recipe: ft_lib_dir={}'.format(ft_lib_dir))
         info('reportlab recipe: ft_inc_dir={}'.format(ft_inc_dir))
         with current_directory(recipe_dir):
             sh.ls('-lathr')
             ensure_dir(tmp_dir)
             pfbfile = os.path.join(tmp_dir, "pfbfer-20070710.zip")
             if not os.path.isfile(pfbfile):
                 sh.wget("http://www.reportlab.com/ftp/pfbfer-20070710.zip", "-O", pfbfile)
             sh.unzip("-u", "-d", os.path.join(recipe_dir, "src", "reportlab", "fonts"), pfbfile)
             if os.path.isfile("setup.py"):
                 with open('setup.py', 'rb') as f:
                     text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir)
                 with open('setup.py', 'wb') as f:
                     f.write(text)
开发者ID:yileye,项目名称:python-for-android,代码行数:28,代码来源:__init__.py


示例4: test_glob_expansion

def test_glob_expansion():
    # TODO: error
    import sh

    # this will not work
    sh.ls('*.py')

    sh.ls(sh.glob('*.py'))
开发者ID:vhnuuh,项目名称:pyutil,代码行数:8,代码来源:sample.py


示例5: test_command_execution

def test_command_execution():
    import sh
    print sh.ls('/')

    from sh import ls
    print ls('/')

    run = sh.Command('/home/echo.sh')
    run()
开发者ID:vhnuuh,项目名称:pyutil,代码行数:9,代码来源:sample.py


示例6: test_no_pipe

    def test_no_pipe(self):
        from sh import ls

        p = ls()
        self.assertFalse(p.process._pipe_queue.empty())

        def callback(line): pass
        p = ls(_out=callback)
        self.assertTrue(p.process._pipe_queue.empty())

        p = ls(_no_pipe=True)
        self.assertTrue(p.process._pipe_queue.empty())
开发者ID:0xr0ot,项目名称:sh,代码行数:12,代码来源:test.py


示例7: test_ok_code

 def test_ok_code(self):
     from sh import ls, ErrorReturnCode_1, ErrorReturnCode_2
     
     exc_to_test = ErrorReturnCode_2
     code_to_pass = 2
     if IS_OSX:
         exc_to_test = ErrorReturnCode_1
         code_to_pass = 1
     self.assertRaises(exc_to_test, ls, "/aofwje/garogjao4a/eoan3on")
     
     ls("/aofwje/garogjao4a/eoan3on", _ok_code=code_to_pass)
     ls("/aofwje/garogjao4a/eoan3on", _ok_code=[code_to_pass])
开发者ID:ahhentz,项目名称:sh,代码行数:12,代码来源:test.py


示例8: add_all_files

    def add_all_files(self):
        with CdContext(self.book.local_path):
            sh.git.init('.')

            logging.debug("files to add: " + str(sh.ls()))

            # NOTE: repo.untracked_files is unreliable with CdContext
            # using sh.ls() instead, this doesn't recognize .gitignore
            for _file in sh.ls():
                for _subpath in _file.split():
                    logging.debug("adding file: " + str(_file))

                    self.add_file(_subpath)
开发者ID:gitberg-temp,项目名称:gitberg-archive,代码行数:13,代码来源:make.py


示例9: test_glob_warning

    def test_glob_warning(self):
        from sh import ls
        from glob import glob
        import warnings

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            ls(glob("ofjaoweijfaowe"))

            self.assertTrue(len(w) == 1)
            self.assertTrue(issubclass(w[-1].category, UserWarning))
            self.assertTrue("glob" in str(w[-1].message))
开发者ID:ahhentz,项目名称:sh,代码行数:13,代码来源:test.py


示例10: test_exit_codes

def test_exit_codes():
    from sh import ls, ErrorReturnCode_2, ErrorReturnCode
    output = ls('/')
    print output.exit_code  # should be 0

    # error return code
    try:
        print ls('/some/non-existent')
    except ErrorReturnCode_2:
        print 'folder does not exit!'
    except ErrorReturnCode:
        print 'unknown error'
        exit(1)
开发者ID:vhnuuh,项目名称:pyutil,代码行数:13,代码来源:sample.py


示例11: test_bake_args_come_first

    def test_bake_args_come_first(self):
        from sh import ls
        ls = ls.bake(full_time=True)

        ran = ls("-la").command_ran
        ft = ran.index("full-time")
        self.assertTrue("-la" in ran[ft:])
开发者ID:dschexna,项目名称:fedemo,代码行数:7,代码来源:test.py


示例12: search_yml

    def search_yml(self, request, pk=None):
        yml_dir_all = []
        yml_set = []
        yml_dir_list = request.DATA['pro_ansi_release_yml'].split('/')
	print yml_dir_list
        yml_dir_list.pop()
        yml_dir = '/'.join(yml_dir_list) + '/costume'
        yml_dir_all.append([yml_dir, request.DATA['pro_name']])
        print yml_dir_all
        for i,x in yml_dir_all:
            if os.path.exists(i):
                try:
                    files = sh.ls(i).split()
                except:
                    pass
                else:
                    for j in files:
                        print j
                        with open(i + '/' + j,'r') as f:
                            try:
                                explain = f.readlines()[0].strip().split(':')[1]
                            except:
                                explain = 'no explanation'
                            yml_set.append({'pro_name': x,
                                            'yml_name': j,
                                            'yml_full_distination': i + '/' + j,
                                            'yml_explain': explain})
        return Response(yml_set)
开发者ID:zylhz,项目名称:ansible_release,代码行数:28,代码来源:api_setviews.py


示例13: trial

def trial(num_bins=1, size_bin=500, after_rm=None, max_delta=0.05):
    from sh import imgbase, rm, ls

    def img_free():
        return float(imgbase("layout", "--free-space"))

    imgbase = imgbase.bake("--debug")

    a = img_free()

    [dd(B, size_bin) for B in iter(range(0, num_bins))]
    print("Files which were created")
    print(ls("-shal", *glob.glob("/var/tmp/*.bin")))
    b = img_free()

    print("Files are getting removed")
    rm("-f", *glob.glob("/var/tmp/*.bin"))
    after_rm()
    c = img_free()

    ratio = a / c
    print(a, b, c, ratio)
    delta = 1 - ratio
    assert delta < max_delta, \
        "Delta %s is larger than %s" % (delta, max_delta)
开发者ID:oVirt,项目名称:imgbased,代码行数:25,代码来源:testStorage.py


示例14: getfiles

def getfiles(userpath):
	filepath=[]
	userpath = os.path.abspath(userpath)
	contents=os.walk(userpath)
	temp = contents
	temp_list=list(temp)
	if len(temp_list)==0:	#This means that either the path points to a single file or a non-existent file/folder.
		try:
			with open(userpath) as f:	
				pass	
			return userpath.split()	#Applied split function to convert the string to a list.
		except IOError:
			print 'Invalid path.'
			sys.exit()

	contents=os.walk(userpath)
	raw_files = contents.next()
	files = sh.ls(str(raw_files[0]), '-R')
	files = str(files).split()
	ff = []
	for i in xrange(len(files)):
		if files[i][-1] == ':':
			folder = files[i][:-1]
			continue
		try:
			sh.cd(folder + '/' + files[i])
			continue
		except OSError:
			ff.append(folder + '/' + files[i])
	return ff
开发者ID:ritratt,项目名称:craesy,代码行数:30,代码来源:GetFiles.py


示例15: split_ann

def split_ann(ann_file):
    if 'tmp' not in ls():
        mkdir('tmp')
    parser = BeautifulSoup(open(ann_file))
    for mistake in parser.find_all('mistake'):
        with open('tmp/%s' % mistake.attrs['nid'], 'a') as f:
            f.write(mistake.__str__())
开发者ID:lmc2179,项目名称:ErrorDetection,代码行数:7,代码来源:nucle_flatten.py


示例16: cover_calc

def cover_calc(in_dir, infile):
    all_query_files = sh.ls(in_dir).split()
    all_query_files = [in_dir + "/" + i for i in all_query_files]

    query_dict = collections.defaultdict(int)
    gentime_query_dict = collections.defaultdict(int)

    for fname in all_query_files:
        print "processing", fname
        with open(fname) as f:
            for line in f:
                try:
                    (query, freq) = line.strip().split('\t')
                    query_dict[query] += int(freq)
                except ValueError:
                    pass
    with open(infile) as f:
        for line in f:
            query = line.strip().split('\t')[0]
            gentime_query_dict[query] = query_dict[query]

    total = 0
    gen_freq = 0

    for k in query_dict:
        total += query_dict[k]
    for k in gentime_query_dict:
        gen_freq += gentime_query_dict[k]

    print gen_freq, total, float(gen_freq) / total
开发者ID:akirayu101,项目名称:gentime,代码行数:30,代码来源:cover_calc.py


示例17: test_link_package_repos

def test_link_package_repos(product):
    """Test links made from doc repo to package repos."""
    print(sh.ls('-al', product.doc_dir))

    for package_name, package_data in product.manifest.packages.items():
        print(package_name)
        # test that the package's directory exists in docs
        package_dir = os.path.join(product.build_dir,
                                   product.manifest.doc_repo_name,
                                   str(package_name))
        print(package_dir)
        assert os.path.isdir(package_dir)

        # test that the packages doc/_static directory is linked
        package_static_dir = os.path.join(package_data['dir'],
                                          'doc', '_static', package_name)
        if os.path.exists(package_static_dir):
            doc_package_static_dir = os.path.join(product.doc_dir,
                                                  '_static', str(package_name))
            assert os.path.islink(doc_package_static_dir)
            assert os.path.isdir(doc_package_static_dir)

        # test that individual entities of a package's doc (aside from _static)
        # are linked
        source_dir = os.path.join(package_data['dir'], 'doc')
        print('source_dir', source_dir)
        print(os.listdir(source_dir))
        target_dir = os.path.join(product.doc_dir, str(package_name))
        for entity in os.listdir(source_dir):
            print('entity', entity)
            if entity in product.package_excludes:
                continue
            link_name = os.path.join(target_dir, entity)
            assert os.path.islink(link_name)
            assert os.path.lexists(link_name)
开发者ID:lsst-sqre,项目名称:ltd-mason,代码行数:35,代码来源:test_product.py


示例18: test_bake_args_come_first

 def test_bake_args_come_first(self):
     from sh import ls
     ls = ls.bake(h=True)
     
     ran = ls("-la").ran
     ft = ran.index("-h")
     self.assertTrue("-la" in ran[ft:]) 
开发者ID:ahhentz,项目名称:sh,代码行数:7,代码来源:test.py


示例19: test_incremental_composition

 def test_incremental_composition(self):
     from sh import ls, wc
     c1 = int(wc(ls("-A1", _piped=True), l=True).strip())
     c2 = len(os.listdir("."))
     if c1 != c2:
         with open("/tmp/fail", "a") as h: h.write("FUCK\n")
     self.assertEqual(c1, c2)
开发者ID:ahhentz,项目名称:sh,代码行数:7,代码来源:test.py


示例20: test_background_exception

 def test_background_exception(self):
     from sh import ls, ErrorReturnCode_1, ErrorReturnCode_2
     p = ls("/ofawjeofj", _bg=True) # should not raise
     
     exc_to_test = ErrorReturnCode_2
     if IS_OSX: exc_to_test = ErrorReturnCode_1
     self.assertRaises(exc_to_test, p.wait) # should raise
开发者ID:ahhentz,项目名称:sh,代码行数:7,代码来源:test.py



注:本文中的sh.ls函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sh.make函数代码示例发布时间:2022-05-27
下一篇:
Python sh.grep函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap