当前位置: 首页>>代码示例>>Python>>正文


Python utils.which函数代码示例

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


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

示例1: run_mongo_restore

    def run_mongo_restore(self, restore, destination_uri, dump_dir, source_database_name,
                          log_file_name, dump_log_file_name,
                          exclude_system_users=None,
                          exclude_admin_system_users=None,
                          exclude_system_roles=None,
                          options=None):

        if source_database_name:
            source_dir = os.path.join(dump_dir, source_database_name)
        else:
            source_dir = dump_dir

        workspace = self.get_task_workspace_dir(restore)
        # IMPORTANT delete dump log file so the restore command would not break
        dump_log_path = os.path.join(workspace, dump_dir, dump_log_file_name)
        if os.path.exists(dump_log_path):
            os.remove(dump_log_path)

        if exclude_system_users:
            self._delete_system_users_from_dump(restore, source_dir)

        if exclude_admin_system_users:
            self._delete_admin_system_users_from_dump(restore, source_dir)

        if exclude_system_roles:
            self._delete_roles_from_dump(restore, source_dir)

        working_dir = workspace
        log_path = os.path.join(workspace, log_file_name)

        restore_cmd = [
            which("mongoctl"),
            "restore",
            destination_uri,
            source_dir
        ]

        if options:
            restore_cmd.extend(options)

        restore_cmd_display = restore_cmd[:]

        restore_cmd_display[restore_cmd_display.index("restore") + 1] = mask_mongo_uri(destination_uri)

        logger.info("Running mongoctl restore command: %s" %
                    " ".join(restore_cmd_display))

        returncode = execute_command_wrapper(restore_cmd,
                                             output_path=log_path,
                                             cwd=working_dir)

        # read the last dump log line
        last_line_tail_cmd = [which('tail'), '-1', log_path]
        last_log_line = execute_command(last_line_tail_cmd)

        if returncode:
            raise RestoreError(returncode, last_log_line)
开发者ID:mongolab,项目名称:mongodb-backup-system,代码行数:57,代码来源:backup_assistant.py

示例2: __init__

 def __init__(self, queue, condition, dbpath):
     threading.Thread.__init__(self, name="FiledataThread")
     self.queue = queue
     self.condition = condition
     self.dbpath = dbpath
     self.running = True
     self.soxi = which('soxi')
     self.sox = which('sox')
     self.soundstretch = which('soundstretch')
开发者ID:radiocicletta,项目名称:Scriptcicletti,代码行数:9,代码来源:remote.py

示例3: archlinux_env

def archlinux_env():
    if utils.which('yaourt'):
        pacman = 'yaourt'
    elif utils.which('pacman'):
        pacman = 'sudo pacman'
    else:
        return False, None

    enabled_by_default = utils.which('pkgfile')

    return enabled_by_default, pacman
开发者ID:jeinglis,项目名称:thefuckServer,代码行数:11,代码来源:archlinux.py

示例4: serveur

def serveur():
    serveur_menu = menu.Menu()
    serveur_menu_selection = serveur_menu.show(
        {
            utils.SERVEUR_APACHE: u'Apache',
            utils.SERVEUR_LIGHTTPD: u'Lighttpd'
        }, u'Menu installation serveur')

    if serveur_menu_selection == utils.SERVEUR_APACHE:
        if utils.which('apache2') is None:
            print(u'_____ Installation d''apache _____')
            os.system('apt-get -y install apache2')
        else:
            print(u'Apache est déjà installé')
    elif serveur_menu_selection == utils.SERVEUR_LIGHTTPD:
        if utils.which('lighttpd') is None:
            print(u'_____ Installation de lighttpd _____')
            os.system('apt-get -y install lighttpd')

            f = open('/etc/php5/cgi/php.ini', 'r')
            file_data = f.read()
            f.close()

            new_data = file_data.replace(';cgi.fix_pathinfo=1', 'cgi.fix_pathinfo=1')

            f = open('/etc/php5/cgi/php.ini', 'w')
            f.write(new_data)
            f.close()

            os.system('lighttpd-enable-mod fastcgi')
            os.system('lighttpd-enable-mod fastcgi-php')
            os.system('/etc/init.d/lighttpd force-reload')
            os.system('/bin/echo \'## directory listing configuration## we disable the directory listing by default##$HTTP["url"] =~ "^/" {  dir-listing.activate = "disable"}\' | /usr/bin/tee /etc/lighttpd/conf-available/20-disable-listing.conf')
            os.system('/usr/sbin/lighty-enable-mod disable-listing')
            os.system('/etc/init.d/lighttpd force-reload')

            f = open('/etc/lighttpd/lighttpd.conf', 'r')
            file_data = f.read()
            f.close()

            new_data = file_data.replace('#       "mod_rewrite"', '        "mod_rewrite"')
            new_data = new_data + '\r\n server.error-handler-404 = "/index.php?error=404"'

            f = open('/etc/lighttpd/lighttpd.conf', 'w')
            f.write(new_data)
            f.close()

            os.system('/etc/init.d/lighttpd force-reload')
        else:
            print(u'Lighttpd est déjà installé')

    return serveur_menu_selection
开发者ID:capic,项目名称:installeur,代码行数:52,代码来源:common.py

示例5: mux_audio_video

def mux_audio_video(file_name, output_dir):
	"""
		Rebuild the AVI container for source file with hardsubbed video track
		:param filename: Name of the file that had to be reencoded
		:type filename: str 
		:param output_dir: Directory where to place raw hardsubbed video
		:type output_dir: str
	"""
	list_of_files = [f for f in os.listdir(output_dir)  if re.match(r'.*\.(xvid|audio)', f)]
	input_param = []
	map_param = []
	count = 0
	for f in reversed(list_of_files):
		if f[-5:] == '.xvid':
			video_file = '-i "' + output_dir + os.sep + f + '"'
		else:
			count = count + 1
			input_param.append('-i "' + output_dir + os.sep + f + '"')
			map_param.append('-map ' + str(count) + ':0')

	# Gather data for the progress bar.
	# If you have ffmpeg you have ffprobe, so it is not checked in REQUIRED_EXECUTABLES
	command = '{ffprobe} -show_streams "{video_input}"'.format(
		ffprobe=which('ffprobe')[0],
                video_input=output_dir + os.sep + f,
	)
	thread = pexpect.spawn(command)
	pl = thread.compile_pattern_list([
		pexpect.EOF,
		"nb_frames=(\d+)"
		])
	while True:
		i = thread.expect_list(pl, timeout=None)
		if i == 0:  # EOF, Process exited
			break
		if i == 1:  # Status
			tot_frames = int(thread.match.group(1))
	thread.close()	 

	command = '{ffmpeg} -y {video_input} {input_params} -c copy -map 0:0 {map_params} "{dest_file}"'.format(
		ffmpeg=which('ffmpeg')[0],
                video_input=video_file,
		input_params=' '.join(input_param),
		map_params=' '.join(map_param),
		dest_file=output_dir + os.sep + os.path.basename(file_name)
	)
	launch_process_with_progress_bar(command, REQUIRED_EXECUTABLES['ffmpeg'], tot_frames, 'Rebuilding file: ', verbose, debug)
	# Cleaning some mess
	for f in reversed(list_of_files):
		os.remove(output_dir + os.sep + f) 
开发者ID:torre76,项目名称:hardsub,代码行数:50,代码来源:avi.py

示例6: __zcat

def __zcat():
    """
    get the path to the zcat/gzcat executable
    or raise an exception
    """
    global __zcat_path
    if __zcat_path is not None:
        return __zcat_path

    __zcat_path = which("gzcat")
    if not __zcat_path:
        __zcat_path = which("zcat")
    if not __zcat_path:
        raise ValueError("Unable to find a zcat|gzcat executable in PATH!")
    return __zcat_path
开发者ID:maikroeder,项目名称:gemtools,代码行数:15,代码来源:files.py

示例7: generate_new_keypair

def generate_new_keypair(self, settings):
    """
    Calls :func:`openssh_generate_new_keypair` or
    :func:`dropbear_generate_new_keypair` depending on what's available on the
    system.
    """
    self.ssh_log.debug('generate_new_keypair()')
    users_ssh_dir = get_ssh_dir(self)
    name = 'id_ecdsa'
    keytype = None
    bits = None
    passphrase = ''
    comment = ''
    if 'name' in settings:
        name = settings['name']
    if 'keytype' in settings:
        keytype = settings['keytype']
    if 'bits' in settings:
        bits = settings['bits']
    if 'passphrase' in settings:
        passphrase = settings['passphrase']
    if 'comment' in settings:
        comment = settings['comment']
    log_metadata = {
        'name': name,
        'keytype': keytype,
        'bits': bits,
        'comment': comment
    }
    self.ssh_log.info("Generating new SSH keypair", metadata=log_metadata)
    if which('ssh-keygen'): # Prefer OpenSSH
        openssh_generate_new_keypair(
            self,
            name, # Name to use when generating the keypair
            users_ssh_dir, # Path to save it
            keytype=keytype,
            passphrase=passphrase,
            bits=bits,
            comment=comment
        )
    elif which('dropbearkey'):
        dropbear_generate_new_keypair(self,
            name, # Name to use when generating the keypair
            users_ssh_dir, # Path to save it
            keytype=keytype,
            passphrase=passphrase,
            bits=bits,
            comment=comment)
开发者ID:ArneBab,项目名称:GateOne,代码行数:48,代码来源:ssh.py

示例8: test_run_compress

def test_run_compress():

    if which('nccopy') is None:
        print("Could not find nccopy in path")
        assert(False)
    # retdict = nccompress.run_nccopy('simple_xy.nc','simple_xy.run_nccopy.nc',level=3,verbose=False,shuffle=True)
    # pdb.set_trace()
    retdict = nccompress.run_compress('simple_xy.nc','simple_xy.run_nccopy.nc',level=3,verbose=True,shuffle=True,nccopy=True,timing=False)
    print(retdict)
    assert (retdict['orig_size']/retdict['comp_size'] >= 5.)
    assert (retdict['dlevel'] == 3)
    assert retdict['shuffle']
    assert nccompress.are_equal('simple_xy.nc','simple_xy.run_nccopy.nc',verbose=True)

    # This requires nc2nc to be in the path. If nccompress/nc2nc.py has changed this will not be reflect
    # any change until installation. This is a test for nccompres to correctly call nc2nc
    retdict = nccompress.run_compress('simple_xy.nc','simple_xy.run_nc2nc.nc',level=3,verbose=True,shuffle=True,nccopy=False,timing=False)
    print(retdict)
    assert (retdict['orig_size']/retdict['comp_size'] >= 5.)
    assert (retdict['dlevel'] == 3)
    assert retdict['shuffle']

    assert nccompress.are_equal('simple_xy.nc','simple_xy.run_nc2nc.nc',verbose=True)

    assert nccompress.are_equal('simple_xy.run_nc2nc.nc','simple_xy.run_nccopy.nc',verbose=True)
开发者ID:coecms,项目名称:nccompress,代码行数:25,代码来源:test_nccompress.py

示例9: find_java

def find_java():
    required_major = 1
    required_minor = 7
    exec_command = None
    has_server_jvm = True
    java_path = utils.which('java')

    if not java_path:
        print 'NOTE: No Java executable found in $PATH.'
        sys.exit(1)

    is_ok = False
    java_version_out, _ = popen([java_path, '-version']).communicate()
    # pylint: disable=E1103
    match = re.search(java_build_regex, java_version_out)
    if match:
        major = int(match.group(1))
        minor = int(match.group(2))
        is_ok = major >= required_major and minor >= required_minor
    if is_ok:
        exec_command = [java_path, '-Xms1024m', '-server', '-XX:+TieredCompilation']
        check_server_proc = popen(exec_command + ['-version'])
        check_server_proc.communicate()
        if check_server_proc.returncode != 0:
            # Not all Java installs have server JVMs.
            exec_command = exec_command.remove('-server')
            has_server_jvm = False

    if not is_ok:
        print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (required_major, required_minor)
        sys.exit(1)
    print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)')
    return exec_command
开发者ID:easingthemes,项目名称:devtools-frontend,代码行数:33,代码来源:compile_frontend.py

示例10: mux_audio_video

def mux_audio_video(file_name, output_dir):
	"""
		Rebuild the MP4 container for source file with hardsubbed video track
		:param filename: Name of the file that had to be reencoded
		:type filename: str 
		:param output_dir: Directory where to place raw hardsubbed video
		:type output_dir: str
	"""
        base_file_name = get_base_file_name(file_name)
	list_of_files = [f for f in os.listdir(output_dir) if re.match(base_file_name + r'.*\.(264|aac|audio)', f)]
	file_param = []
	for f in reversed(list_of_files):
		file_param.append('-add "' + output_dir + os.sep + f + '"')

	# If the destination file already exists, MP4Box adds the new tracks to it
	output_file = output_dir + os.sep + os.path.basename(file_name)
	index_out = 0
	while os.path.isfile(output_file):
		print (colorama.Style.BRIGHT + 'File ' + output_file + ' already exists' + colorama.Style.NORMAL);
		index_out = index_out + 1
		output_file = output_dir + os.sep + os.path.basename(file_name) + '_' + str(index_out)

	command = '{MP4Box} {add_audio_opts} "{dest_file}"'.format(
		MP4Box = which('MP4Box')[0],
		add_audio_opts = ' '.join(file_param),
		dest_file = output_file
	)
	launch_process_with_progress_bar(command, REQUIRED_EXECUTABLES['MP4Box'], 100, 'Rebuilding file: ', verbose, debug)
	# Cleaning some mess
	for f in reversed(list_of_files):
		os.remove(output_dir + os.sep + f) 
开发者ID:torre76,项目名称:hardsub,代码行数:31,代码来源:mp4.py

示例11: resolve_node_paths

def resolve_node_paths():
    if has_valid_global_node():
        if sys.platform == "win32":
            return (utils.which('node'), utils.which('npm.cmd'))
        return (utils.which('node'), utils.which('npm'))
    has_installed_local_node = path.isfile(local_node_binary_path)
    if has_installed_local_node:
        return (local_node_binary_path, local_npm_binary_path)
    if path.isdir(local_node_runtimes_path):
        shutil.rmtree(local_node_runtimes_path)
    if sys.platform == 'linux2' or sys.platform == 'darwin':
        install_node()
        return (local_node_binary_path, local_npm_binary_path)
    print('ERROR: Please install the latest node.js LTS version using the Windows installer:')
    print('https://nodejs.org/en/download/')
    raise
开发者ID:easingthemes,项目名称:devtools-frontend,代码行数:16,代码来源:install_node_deps.py

示例12: open_sub_channel

def open_sub_channel(term, tws):
    """
    Opens a sub-channel of communication by executing a new shell on the SSH
    server using OpenSSH's `Master mode <http://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing>`_
    capability (it spawns a new slave) and returns the resulting
    :class:`termio.Multiplex` instance.  If a slave has already been opened for
    this purpose it will re-use the existing channel.
    """
    logging.debug("open_sub_channel() term: %s" % term)
    global OPEN_SUBCHANNELS
    if term in OPEN_SUBCHANNELS and OPEN_SUBCHANNELS[term].isalive():
        # Use existing sub-channel (much faster this way)
        return OPEN_SUBCHANNELS[term]
    # NOTE: When connecting a slave via ssh you can't tell it to execute a
    # command like you normally can (e.g. 'ssh [email protected] <some command>').  This
    # is why we're using the termio.Multiplex.expect() functionality below...
    session = tws.session
    session_dir = tws.settings['session_dir']
    session_path = os.path.join(session_dir, session)
    if not session_path:
        raise SSHMultiplexingException(_(
            "SSH Plugin: Unable to open slave sub-channel."))
    socket_path = None
    # Find the SSH socket path...
    for f in os.listdir(session_path):
        if f.startswith('ssh:%s:' % term):
            # Grab the SSH socket path from the file
            for line in open(os.path.join(session_path, f)):
                if line.startswith('SSH_SOCKET'):
                    # NOTE: This will includes quotes (which is fine):
                    socket_path = line.split('=')[1].strip()
    # Interesting: When using an existing socket you don't need to give it all
    # the same options as you used to open it but you still need to give it
    # *something* in place of the hostname or it will report a syntax error and
    # print out the help.  So that's why I've put 'go_ssh_remote_cmd' below.
    # ...but I could have just used 'foo' :)
    if not socket_path:
        raise SSHMultiplexingException(_(
            "SSH Plugin: Unable to open slave sub-channel."))
    users_ssh_dir = get_ssh_dir(tws)
    ssh_config_path = os.path.join(users_ssh_dir, 'config')
    if not os.path.exists(ssh_config_path):
        # Create it (an empty one so ssh doesn't error out)
        with open(ssh_config_path, 'w') as f:
            f.write('\n')
    # Hopefully 'go_ssh_remote_cmd' will be a clear enough indication of
    # what is going on by anyone that has to review the logs...
    ssh = which('ssh')
    ssh_command = '%s -x -S%s -F%s go_ssh_remote_cmd' % (
        ssh, socket_path, ssh_config_path)
    logging.debug("ssh_command: %s" % ssh_command)
    OPEN_SUBCHANNELS[term] = m = tws.new_multiplex(
        ssh_command, "%s (sub)" % term)
    # Using huge numbers here so we don't miss much (if anything) if the user
    # executes something like "ps -ef".
    fd = m.spawn(rows=100, cols=200) # Hopefully 100/200 lines/cols is enough
    # ...if it isn't, well, that's not really what this is for :)
    # Set the term title so it gets a proper name in the logs
    m.writeline(u'echo -e "\\033]0;Term %s sub-channel\\007"' % term)
    return m
开发者ID:PaulReiber,项目名称:GateOne,代码行数:60,代码来源:ssh.py

示例13: extract_audio

def extract_audio(file_name, output_dir):
	"""
		Extract all audio tracks from a AVI container
		:param filename: Name of the file that contains audio track
		:type filename: str 
		:param output_dir: Directory where to place raw audio track
		:type output_dir: str	
	"""
	# detect how many audio track
	command = '{mplayer} -noconfig all -cache-min 0 -vo null -ao null -frames 0 -identify "{input_file}" 2>/dev/null | grep ID_AUDIO_ID'.format(mplayer=which('mplayer')[0], input_file=file_name)
	if verbose:
		print command
	thread = pexpect.spawn(command)
	pl = thread.compile_pattern_list([
		pexpect.EOF,
		"ID_AUDIO_ID=(\d+).*"
		])
	audio_tracks = []
	while True:
		i = thread.expect_list(pl, timeout=None)
		if i == 0:  # EOF, Process exited
			break
		if i == 1:  # Status
			audio_tracks.append(int(thread.match.group(1)))	
	thread.close()	 
	# Now extract each audio track
	for track in audio_tracks:
		t_command = '{mplayer} -aid {track} -dumpaudio -dumpfile {dest_file} "{input_file}"'.format(
			mplayer=which("mplayer")[0],
			input_file=file_name,
			track=track,
			dest_file=output_dir + os.sep + "{}".format(track) + ".audio"
		)
		launch_process_with_progress_bar(t_command, REQUIRED_EXECUTABLES['mplayer'], 100, 'Extract audio track {}: '.format(track), verbose, debug)
开发者ID:torre76,项目名称:hardsub,代码行数:34,代码来源:avi.py

示例14: dump_backup

    def dump_backup(self, backup, uri, destination, log_file_name, options=None):
        mongoctl_exe = which("mongoctl")
        if not mongoctl_exe:
            raise MBSError("mongoctl exe not found in PATH")

        dump_cmd = [mongoctl_exe, "--noninteractive", "dump", uri, "-o", destination]

        if options:
            dump_cmd.extend(options)

        dump_cmd_display = dump_cmd[:]
        # mask mongo uri
        dump_cmd_display[3] = mask_mongo_uri(uri)

        logger.info("Running dump command: %s" % " ".join(dump_cmd_display))

        workspace = self.get_task_workspace_dir(backup)
        log_path = os.path.join(workspace, destination, log_file_name)
        last_error_line = {"line": ""}

        def capture_last_error(line):
            if is_mongo_error_log_line(line):
                last_error_line["line"] = line
        # execute dump command
        return_code = execute_command_wrapper(dump_cmd, cwd=workspace, output_path=log_path,
                                             on_output=capture_last_error)

        # raise an error if return code is not 0
        if return_code:
            errors.raise_dump_error(return_code, last_error_line["line"])
开发者ID:mongolab,项目名称:mongodb-backup-system,代码行数:30,代码来源:backup_assistant.py

示例15: create_config_file

def create_config_file(config_file, random_music_home):
    """
    Create a configuration file.

    :param config_file: path to config file we are creating
    :type config_file: str
    :param random_music_home: home of random_music application (i.e. where 
    index files are stored
    :type random_music_home: str
    """
    sys.stdout.write("You do not appear to have a config file, lets create one!\n")
    sys.stdout.write("Creating config file at %s\n" % config_file)
    config = RawConfigParser()
    config.add_section('config')
    config.set('config', 'loop_songs', 'true')
    config.set('config', 'randomise', 'true')
    config.set('config', 'index_dir', os.path.join(random_music_home, 
                                                   "indicies"))
    music_client = DEFAULT_MUSIC_CLIENT
    while not which(music_client):
        music_client = raw_input("The music player '%s' could not be found "
                                   "on your path. Please input a different "
                                   "music player:" % music_client)   
    
    config.set('config', 'music_client', music_client) 

    user_music_dirs = ""
    while not all([os.path.isdir(d) for d in user_music_dirs.split(",")]):
        user_music_dirs = raw_input("Input a csv list of full paths to "
                                   "your music dirs:")
    config.set('config', 'music_dirs', user_music_dirs)
            
    with open(config_file, 'wb') as fh:
        config.write(fh)
开发者ID:caoilteguiry,项目名称:random_music,代码行数:34,代码来源:random_music.py


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