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

Python sh.sed函数代码示例

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

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



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

示例1: env_init

def env_init(site_name=SITE_NAME):
    '''Initialize with this site hostname.'''
    print(green("Initializing new site configuration..."))

    #
    # Generate secret key and update config file
    #
    import random
    import string

    CHARS = string.ascii_letters + string.digits
    SECRET_KEY = "".join([random.choice(CHARS) for i in range(50)])

    print(blue("Configuring the secret key..."))
    os.chdir(PROJ_DIR)
    try:
        sh.sed("-i ",
               "s/SECRET_KEY *=.*/SECRET_KEY = '{0}'/g".format(SECRET_KEY),
               "{0}/config.py".format(APP_NAME))
    except sh.ErrorReturnCode:
        print(red("Could not configure SECRET_KEY for config.py"))
        exit(1)

    #
    # Set the site name, the user defined site hostname
    #
    print(blue("Configuring the SITE_NAME '{0}'.".format(site_name)))
    try:
        sh.sed("-i ",
               "s/SITE_NAME *=.*/SITE_NAME = '{0}'/g".format(site_name),
               "{0}/config.py".format(APP_NAME))
    except sh.ErrorReturnCode:
        print(red("Could not configure SITE_NAME for config.py"))
        exit(1)
开发者ID:DamnedFacts,项目名称:flask-boilerplate,代码行数:34,代码来源:fabfile.py


示例2: main

def main(logger=mylog.default_logger()):
    # load arguments and logger
    arguments = docopt(__doc__, version='0.0')
    # print arguments
    # script self name
    self_name=os.path.basename(sys.argv[0])
    # log
    # logfile=self_name.replace('py','log')
    # logger=set_mylogger(arguments,logfile)
    # load config
    # main_config=load_config('.ll')

    # set filename varibles
    # main_title=os.path.basename(os.getcwd())
    # markdown_file_name=os.path.join(os.getcwd(),'build',main_title+'.markdown')
    # docx_file_name=main_title+'.docx'
    # rtf_file_name=main_title+'.rtf'

    md_pattern=re.compile(r'\.md$')

    markdown_file_name=arguments.get('<filename>')
    if markdown_file_name:
        if os.path.isdir(markdown_file_name):
            walk_sed(markdown_file_name)
        else:
            sh.sed('-i','-e','s/^#//',markdown_file_name)
            # sh.sed('-i','-e','s/^#/'+'#/',markdown_file_name)
    else:
        walk_sed('.')
开发者ID:lhrkkk,项目名称:auto,代码行数:29,代码来源:uplevel.py


示例3: check_upgrade

def check_upgrade():
        server_file = curl(PIFM_HOST + '/client_agent/pifm_agent.py')
        server_sum = awk(
                        md5sum(
                            grep(server_file, '-v', '^PIFM_HOST')
                        ), '{print $1}'
        )

        local_sum = awk(
                        md5sum(
                            grep('-v', '^PIFM_HOST', OUR_SCRIPT)
                        ), '{print $1}'
        )

        if str(server_sum) != str(local_sum):
            logging.info(
                "server: {server}, local: {local}, should update.".format(
                    server=server_sum,
                    local=local_sum
                )
            )
            with open(TMP_SCRIPT, 'w') as f:
                f.write(str(server_file))
            sed('-i',
                "0,/def/ s#http://pi_director#{myhost}#".format(myhost=PIFM_HOST),
                OUR_SCRIPT
                )
            status = python('-m', 'py_compile', TMP_SCRIPT)
            if (status.exit_code == 0):
                shutil.copy(TMP_SCRIPT, OUR_SCRIPT)
                os.chmod(OUR_SCRIPT, 0755)
                sys.exit(0)
开发者ID:artschwagerb,项目名称:pi_director,代码行数:32,代码来源:pifm_agent.py


示例4: html_output

    def html_output(self):
        ext = '.html'
        today = datetime.date.today().isoformat()
        sha = self.test_file + ".html.sha"
        # cannot recover if generating html fails
        options = (['--zip'] + self.options
                   + ['-f', 'html', self.test_file,
                      self.test_out + ext + '.zip'])
        try:
            self.gdoc_to(*options,
                         _err=self.test_err + ".html.log")
            # XXX it hangs without -n, didn't have time to figure out why
            out_dir = os.path.dirname(self.test_out)
            sh.unzip('-n', '-d', out_dir, self.test_out + ext + '.zip')
            sh.sed('-i', '-e', 's/%s/TODAYS_DATE/g' % today,
                   self.test_out + ext)
            test_result = slurp('%s.html' % self.test_out)
        except ErrorReturnCode as e:
            self.say(red("gdoc-to failed: {}. See {}.html.log"),
                     e, self.test_err)
            self.say(red("Ran in {}"), os.getcwd())
            self.failed = True
            sh.rm('-f', sha)
            return
        try:
            html5check(self.test_out + ext,
                       _out=self.test_out + ".html.errors")
        except ErrorReturnCode:
            self.say(red("Test output did not validate as XHTML5!"))
            self.say(red("\tSee {}.html.errors"), self.test_out)
            self.failed = True

        if test_result != slurp(self.test_file + ext):
            # the file changed, but the change might be okay
            spit(self._canonical_body(self.test_out + ext),
                 self.test_out + ".body")
            spit(self._canonical_body(self.test_file + ext),
                 self.test_out + ".canon.body")

            if (slurp(self.test_out + '.body')
                    == slurp(self.test_out + '.canon.body')):
                self.say(yellow("File changed. Updating canonical file."))
                sh.cp(self.test_out + ext, self.test_file + ext)
            else:
                self.say(red("HTML body changed!"))
                self.say(red("\tSee {}.*"), fail_path(self.test_name))
                sh.cp(self.test_out + ext, fail_path(self.test_name + ext))
                sh.diff('-u', self.test_file + ext, self.test_out + ext,
                        _out=fail_path(self.test_name + ".html.diff"),
                        _ok_code=[0, 1])
                sh.cp(self.test_out + ".body",
                      fail_path(self.test_name + ".body"))
                sh.cp(self.test_out + ".canon.body",
                      fail_path(self.test_name + ".body.expected"))
                sh.diff('-u', self.test_out + ".canon.body",
                        self.test_out + ".body",
                        _out=fail_path(self.test_name + '.body.diff'),
                        _ok_code=[0, 1])
                self.failed = True
开发者ID:hybrid-publishing-lab,项目名称:typesetr-academic,代码行数:59,代码来源:run_tests.py


示例5: walk_sed

def walk_sed(dirname):
    md_pattern=re.compile(r'\.md$')
    list_dirs=os.walk(dirname)
    for root,dirs,files in list_dirs:
        for f in files:
            if md_pattern.search(f):

                sh.sed('-i','-e','s/^#//',os.path.join(root, f))
开发者ID:lhrkkk,项目名称:auto,代码行数:8,代码来源:uplevel.py


示例6: _add_description

    def _add_description(self):
        """ adds description to control file"""
        if not self.description or not len(self.description) <= 60:
            logger.warning('bad description, using default pattern')
            self.description = '{} Package'.format(self.package_name)

        sh.sed('-i', r'/^Description/c\\Description: {}'
               .format(self.description),
               self.debian_package_path + '/debian/control').wait()
开发者ID:urban48,项目名称:debpackager,代码行数:9,代码来源:debain_package_manager.py


示例7: _add_deb_dependencies

    def _add_deb_dependencies(self):
        """ adds deb dependencies to control file """
        if self.dependencies:
            debian_dependencies = self.dependencies_to_debian_format(
                self.dependencies)
            dependencies_str = ', '.join(debian_dependencies)

            sh.sed('-i', r'/^Depends/c\\Depends: ${{misc:Depends}}, {}'
                   .format(dependencies_str),
                   self.debian_package_path + '/debian/control').wait()
开发者ID:urban48,项目名称:debpackager,代码行数:10,代码来源:debain_package_manager.py


示例8: add_pr_to_checkout

def add_pr_to_checkout(repo, pr_id, head_sha1, pr_branch, spec):
    sh.curl(
        '-s', '-k', '-L',
        "https://github.com/crowbar/%s/compare/%s...%s.patch" % (
            repo, pr_branch, head_sha1),
        '-o', 'prtest.patch')
    sh.sed('-i', '-e', 's,Url:.*,%define _default_patch_fuzz 2,',
           '-e', 's,%patch[0-36-9].*,,', spec)
    Command('/usr/lib/build/spec_add_patch')(spec, 'prtest.patch')
    iosc('vc', '-m', "added PR test patch from %s#%s (%s)" % (
        repo, pr_id, head_sha1))
开发者ID:hbcbh1999,项目名称:automation,代码行数:11,代码来源:crowbar-testbuild.py


示例9: phred_13_to_18_sed

 def phred_13_to_18_sed(self, new_path=None, in_place=True):
     """Illumina-1.3 format conversion to Illumina-1.8 format via sed (faster)."""
     # String #
     sed_command = r"""4~4y/@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghi/!"#$%&'\''()*+,-.\/0123456789:;<=>[email protected]/"""
     # Faster with bash utilities #
     if in_place is True:
         sh.sed('-i', sed_command, self.path)
         return self
     # New file #
     if new_path is None: new_fastq = self.__class__(new_temp_path())
     else:                new_fastq = self.__class__(new_path)
     sh.sed(sed_command + " " + new_fastq, self.path)
     return new_fastq
开发者ID:xapple,项目名称:fasta,代码行数:13,代码来源:fastq.py


示例10: dfs_dir

def dfs_dir(root_dir,markdown_file,level,logger=mylog.default_logger()):
    # generate the filelist, ignore the hidden files.
    hiden_file=re.compile(r'^\.|main_title\.md|\.synopsis$|\.markdown')
    effective_file=re.compile(r'(^.*_+|^[0-9]*_*)(.*)\.md$')
    efflists=[ filename for filename in os.listdir(root_dir) if  effective_file.match(filename)]
    efflists_title=[ effective_file.match(filename).group(2) for filename in os.listdir(root_dir) if  effective_file.match(filename)]

    alllists=[ filename for filename in os.listdir(root_dir) if not hiden_file.match(filename)]

    #
    for filename,title in zip(efflists,efflists_title):
        path = os.path.join(root_dir, filename)
        # print logger
        logger.debug(filename+title)


        # write the file content according to level
        #TODO: 文件夹的处理,文件夹名+.md, .synopsis的处理
        if os.path.isdir(path):
            markdown_file.write('#'*level+title)
            markdown_file.write('\n')
            # if os.path.exists(str(path)+'/00.content'):
                # markdown_file.write(str(sh.cat(path+'/00.content'))+'\n')
            dfs_dir(path, markdown_file, level+1)
        else:
            if title:
                markdown_file.write('#'*level+title)
            markdown_file.write('\n')
            markdown_file.write(str(sh.sed('s/^#/'+'#'*level+'#/',path)))
开发者ID:lhrkkk,项目名称:auto,代码行数:29,代码来源:xml_parse.py


示例11: remove_trailing_stars

 def remove_trailing_stars(self, new_path=None, in_place=True, check=False):
     """Remove the bad character that can be inserted by some programs at the
     end of sequences."""
     # Optional check #
     if check and int(sh.grep('-c', '\*', self.path, _ok_code=[0,1])) == 0: return self
     # Faster with bash utilities #
     if in_place is True:
         sh.sed('-i', 's/\*$//g', self.path)
         return self
     # Standard way #
     if new_path is None: new_fasta = self.__class__(new_temp_path())
     else:                new_fasta = self.__class__(new_path)
     new_fasta.create()
     for seq in self: new_fasta.add_str(str(seq.seq).rstrip('*'), seq.id)
     new_fasta.close()
     return new_fasta
开发者ID:guochangjiang,项目名称:fasta,代码行数:16,代码来源:__init__.py


示例12: capture_screen

    def capture_screen(self):
        """
        Use adb shell screencap
        :return: CV2Img
        """
        img = CV2Img()
        result = sed(adb("shell", "screencap", "-p"), 's/\r$//')

        return img.load_binary(result.stdout)
开发者ID:Swind,项目名称:Sikuli-Img,代码行数:9,代码来源:adb_roboot.py


示例13: device_list

def device_list():
    """
    Get udid from iPhone and iPad plugged into the computer
    Returns a list
    """

    # TODO: separate iPhone and iPad
    raw = sh.sed(sh.system_profiler("SPUSBDataType"), "-n", "-e",
                 '/iPad/,/Serial/p', "-e", '/iPhone/,/Serial/p')
    devices = sh.awk(
        sh.grep(raw, "Serial Number:"), "-F", ": ", "{print $2}").split('\n')
    return [device for device in devices if device]
开发者ID:Stupeflix,项目名称:fixxd,代码行数:12,代码来源:device.py


示例14: import_csv

	def import_csv(self, username, userpass, filestream):
		retCode = True
		import_xml_command = sh.Command("/usr/share/ds-matricula-plugin/matricula-common-scripts/1-itaca2mysql")
		# set a temporary filename
		TMP_CSV = tempfile.mkstemp()[1]
		TMP_CSV2 = tempfile.mkstemp()[1]
		if self._put_file(TMP_CSV, filestream):
			TMP_XML = tempfile.mkstemp()[1]
			sh.sed(sh.iconv("-f", "ISO-8859-15", "-t", "UTF-8", TMP_CSV), "-e", "1{s%[[:blank:]]%%g;s%\.%%g;s%[ñÑ]%n%g;s%.*%\L&%}", _out=TMP_CSV2)

			if self._csv2xml(TMP_CSV2, TMP_XML):
				try:
					import_xml_command(TMP_XML)
				except ErrorReturnCode:
					# some error happened
					retCode = False

			os.remove(TMP_XML)
		os.remove(TMP_CSV)
		os.remove(TMP_CSV2)
		return retCode
开发者ID:aurex-linux,项目名称:ds-matricula-plugin,代码行数:21,代码来源:matricula.py


示例15: build_arch

 def build_arch(self, arch):
     options_iphoneos = (
         "-isysroot {}".format(arch.sysroot),
         "-DOPENSSL_THREADS",
         "-D_REENTRANT",
         "-DDSO_DLFCN",
         "-DHAVE_DLFCN_H",
         "-fomit-frame-pointer",
         "-fno-common",
         "-O3"
     )
     build_env = arch.get_env()
     target = arch_mapper[arch.arch]
     shprint(sh.env, _env=build_env)
     sh.perl(join(self.build_dir, "Configure"),
             target,
             _env=build_env)
     if target == 'iphoneos-cross':
         sh.sed("-ie", "s!^CFLAG=.*!CFLAG={} {}!".format(build_env['CFLAGS'],
                " ".join(options_iphoneos)),
                "Makefile")
         sh.sed("-ie", "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;! ",
                "crypto/ui/ui_openssl.c")
     else:
         sh.sed("-ie", "s!^CFLAG=!CFLAG={} !".format(build_env['CFLAGS']),
                "Makefile")
     shprint(sh.make, "clean")
     shprint(sh.make, "-j4", "build_libs")
开发者ID:arcticshores,项目名称:kivy-ios,代码行数:28,代码来源:__init__.py


示例16: set_hostname

    def set_hostname(self, hostname):
        """Update hostname

            Args:
                hostname (str): hostname to be updated
        """
        try:
            old_hostname = self.get_hostname()

            is_valid_hostname(hostname)

            sh.hostname("-b", hostname)
            sh.echo(hostname, _out="/etc/hostname")

            try:
                # sed -i 's/ old$/ new/g' /etc/hosts
                sh.sed("-i", "s/ {}$/ {}/g".format(old_hostname, hostname),
                       "/etc/hosts")
            except:
                with open("/etc/hosts", "a") as f:
                    f.write("127.0.0.1       localhost {}\n".format(hostname))
            self.update(id=1, newObj={"hostname": hostname})
        except Exception as e:
            raise e
开发者ID:Sanji-IO,项目名称:sanji-bundle-status,代码行数:24,代码来源:__init__.py


示例17: get_container_info

def get_container_info():
    container_info = {}

    try:
        container_info['container_name'] = tail(sed(grep(cat('/proc/self/cgroup'), 'docker'), 's/^.*\///'), '-n1')
    except:
        container_info['container_name'] = 'unknown'

    try:
        container_info['app_version'] =  open('version', 'r').read()
    except:
        container_info['app_version'] = 'unknown'


    return container_info
开发者ID:danpilch,项目名称:k8s-automation,代码行数:15,代码来源:app.py


示例18: dfs_dir_byplist

def dfs_dir_byplist(root_dir,markdown_file,level,logger=mylog.default_logger()):
    # generate the filelist, ignore the hidden files.

    effective_file=re.compile(r'(^.*_+|^[0-9]*_*)(.*)\.md$')
    plist_file_name=os.path.join(root_dir,'.Ulysses-Group.plist')
    print plist_file_name
    print root_dir, level
    filename_list,dirname_list=get_name_from_plist(plist_file_name)
    print filename_list
    alllists=filename_list+dirname_list
    efflists=[ filename for filename in filename_list if  effective_file.match(filename)]+dirname_list
    print efflists
    # efflists_title=[ effective_file.match(filename).group(2) for filename in alllists if  effective_file.match(filename)]


    #

    for filename in efflists:
        path = os.path.join(root_dir, filename)
        # print logger
        # logger.debug(filename+title)


        # write the file content according to level
        #TODO: 文件夹的处理,文件夹名+.md, .synopsis的处理
        if os.path.isdir(path):
            # markdown_file.write('#'*level+title)
            # markdown_file.write('\n\n')
            # if os.path.exists(str(path)+'/00.content'):
                # markdown_file.write(str(sh.cat(path+'/00.content'))+'\n')
            dfs_dir_byplist(path, markdown_file, level+1)
        else:
            # if title:
                # markdown_file.write('#'*level+title)
            # markdown_file.write('\n\n')
            # markdown_file.write(str(sh.sed('s/^#/'+'#'*level+'#/',path)))
            markdown_file.write(str(sh.sed('s/^#/'+'#'+'/',path)))
            markdown_file.write('\n\n')
开发者ID:lhrkkk,项目名称:auto,代码行数:38,代码来源:makemd.py


示例19: add

 def add(source_repo, f, apt_file):
     if not re.search(source_repo, f.read()):
         lgr.debug('Adding source repository {0}'.format(source_repo))
         sh.sed('-i', "2i {0}".format(source_repo), apt_file)
     else:
         lgr.debug('Repo {0} already added.'.format(source_repo))
开发者ID:InGenious-Justice,项目名称:packman,代码行数:6,代码来源:apt.py


示例20: test_stdin_from_string

 def test_stdin_from_string(self):
     from sh import sed
     self.assertEqual(sed(_in="test", e="s/test/lol/").strip(), "lol")
开发者ID:ahhentz,项目名称:sh,代码行数:3,代码来源:test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sh.ssh函数代码示例发布时间:2022-05-27
下一篇:
Python sh.rm函数代码示例发布时间: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