本文整理汇总了Python中os.chdir方法的典型用法代码示例。如果您正苦于以下问题:Python os.chdir方法的具体用法?Python os.chdir怎么用?Python os.chdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.chdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dash_in_project_slug
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def test_dash_in_project_slug(cookies):
ctx = {'project_slug': "my-package"}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例2: ensure_lambda_helper
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def ensure_lambda_helper():
awslambda = getattr(clients, "lambda")
try:
helper_desc = awslambda.get_function(FunctionName="aegea-dev-process_batch_event")
logger.info("Using Batch helper Lambda %s", helper_desc["Configuration"]["FunctionArn"])
except awslambda.exceptions.ResourceNotFoundException:
logger.info("Batch helper Lambda not found, installing")
import chalice.cli
orig_argv = sys.argv
orig_wd = os.getcwd()
try:
os.chdir(os.path.join(os.path.dirname(__file__), "batch_events_lambda"))
sys.argv = ["chalice", "deploy", "--no-autogen-policy"]
chalice.cli.main()
except SystemExit:
pass
finally:
os.chdir(orig_wd)
sys.argv = orig_argv
示例3: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def __init__(self, label="DefaultValues", logfile=None, verbose=False, debug=False):
super(DefaultValues, self).__init__(label=label, logfile=logfile, verbose=verbose, debug=debug)
self._validator = Validator(logfile=logfile, verbose=verbose, debug=debug)
pipeline_dir = os.path.dirname(self._validator.get_full_path(os.path.dirname(scripts.__file__)))
self._DEFAULT_seed = random.randint(0, 2147483640)
self._DEFAULT_tmp_dir = tempfile.gettempdir()
self._DEFAULT_directory_pipeline = pipeline_dir
original_wd = os.getcwd()
os.chdir(pipeline_dir)
file_path_config = os.path.join(pipeline_dir, "default_config.ini")
if self._validator.validate_file(file_path_config, silent=True):
self._from_config(file_path_config)
else:
self._from_hardcoded(pipeline_dir)
os.chdir(original_wd)
示例4: cd
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def cd(self, message, conn):
message = message.split()[1] # 截取目录名
# 如果是新连接或者下载上传文件后的发送则 不切换 只将当前工作目录发送过去
if message != 'same':
f = r'./' + message
os.chdir(f)
# path = ''
path = os.getcwd().split('\\') # 当前工作目录
for i in range(len(path)):
if path[i] == 'resources':
break
pat = ''
for j in range(i, len(path)):
pat = pat + path[j] + ' '
pat = '\\'.join(pat.split())
# 如果切换目录超出范围则退回切换前目录
if 'resources' not in path:
f = r'./resources'
os.chdir(f)
pat = 'resources'
conn.send(pat.encode())
# 判断输入的命令并执行对应的函数
示例5: get_payload_output
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def get_payload_output(payload_output_dir):
""" Builds directory structure if output option is supplied """
output_dir = payload_output_dir
# check to see if the trailing slash has been added to the path : ie /root/path
if not output_dir.endswith("/"):
output_dir = output_dir + "/"
# creates the structure if it doesn't exist
if not os.path.isdir(output_dir):
print(yellowtxt("[!] Creating output directory structure"))
os.mkdir(output_dir)
os.chdir(output_dir)
os.mkdir('handlers')
return output_dir
###############################
### Helper Function ###
###############################
示例6: test_double_quotes_in_name_and_description
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def test_double_quotes_in_name_and_description(cookies):
ctx = {'project_short_description': '"double quotes"',
'full_name': '"name"name'}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例7: test_single_quotes_in_name_and_description
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def test_single_quotes_in_name_and_description(cookies):
ctx = {'project_short_description': "'single quotes'",
'full_name': "Mr. O'Keeffe"}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例8: test_space_in_project_slug
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def test_space_in_project_slug(cookies):
ctx = {'project_slug': "my package"}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例9: test_install
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def test_install(cookies):
project = cookies.bake()
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例10: test_building_documentation_apidocs
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def test_building_documentation_apidocs(cookies):
project = cookies.bake(extra_context={'apidoc': 'yes'})
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
apidocs = project.project.join('docs', '_build', 'html', 'apidocs')
assert apidocs.join('my_python_project.html').isfile()
assert apidocs.join('my_python_project.my_python_project.html').isfile()
示例11: get_mnist
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def get_mnist(data_dir):
if not os.path.isdir(data_dir):
os.system("mkdir " + data_dir)
os.chdir(data_dir)
if (not os.path.exists('train-images-idx3-ubyte')) or \
(not os.path.exists('train-labels-idx1-ubyte')) or \
(not os.path.exists('t10k-images-idx3-ubyte')) or \
(not os.path.exists('t10k-labels-idx1-ubyte')):
import urllib, zipfile
zippath = os.path.join(os.getcwd(), "mnist.zip")
urllib.urlretrieve("http://data.mxnet.io/mxnet/data/mnist.zip", zippath)
zf = zipfile.ZipFile(zippath, "r")
zf.extractall()
zf.close()
os.remove(zippath)
os.chdir("..")
示例12: get_cifar10
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def get_cifar10(data_dir):
if not os.path.isdir(data_dir):
os.system("mkdir " + data_dir)
cwd = os.path.abspath(os.getcwd())
os.chdir(data_dir)
if (not os.path.exists('train.rec')) or \
(not os.path.exists('test.rec')) :
import urllib, zipfile, glob
dirname = os.getcwd()
zippath = os.path.join(dirname, "cifar10.zip")
urllib.urlretrieve("http://data.mxnet.io/mxnet/data/cifar10.zip", zippath)
zf = zipfile.ZipFile(zippath, "r")
zf.extractall()
zf.close()
os.remove(zippath)
for f in glob.glob(os.path.join(dirname, "cifar", "*")):
name = f.split(os.path.sep)[-1]
os.rename(f, os.path.join(dirname, name))
os.rmdir(os.path.join(dirname, "cifar"))
os.chdir(cwd)
# data
示例13: setUp
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def setUp(self):
logging.getLogger().setLevel(logging.DEBUG)
# We need to be in the same directory than the script so the commands in the dockerfiles work as
# expected. But the script can be invoked from a different path
base = os.path.split(os.path.realpath(__file__))[0]
os.chdir(base)
docker_cache._login_dockerhub = MagicMock() # Override login
# Stop in case previous execution was dirty
try:
self._stop_local_docker_registry()
except Exception:
pass
# Start up docker registry
self._start_local_docker_registry()
示例14: install
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def install(self):
"""
Command: Iterate over all AVAILABLE plugins and pre-install them. They can be enabled later.
:return:
"""
print(' >> Installing plugins...')
print(list(self._plugins.items()))
for plugin_name, module in self._plugins.items():
print(' >> Instaling plugin "%s"' % plugin_name)
os.chdir(self._front_path)
print(' .. installing frontend')
module.frontend_setup()
os.chdir('/usr/src/taiga-back/')
print(' .. installing backend')
module.backend_setup()
示例15: test_npm_install_integration
# 需要导入模块: import os [as 别名]
# 或者: from os import chdir [as 别名]
def test_npm_install_integration(self):
remember_cwd(self)
tmpdir = mkdtemp(self)
os.chdir(tmpdir)
stub_mod_call(self, cli)
stub_base_which(self, which_npm)
rt = self.setup_runtime()
rt(['foo', '--install', 'example.package1', 'example.package2'])
with open(join(tmpdir, 'package.json')) as fd:
result = json.load(fd)
self.assertEqual(result['dependencies']['jquery'], '~3.1.0')
self.assertEqual(result['dependencies']['underscore'], '~1.8.3')
# not foo install, but npm install since entry point specified
# the actual runtime instance.
self.assertEqual(self.call_args[0], ([which_npm, 'install'],))