本文整理汇总了Python中unipath.Path.isfile方法的典型用法代码示例。如果您正苦于以下问题:Python Path.isfile方法的具体用法?Python Path.isfile怎么用?Python Path.isfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.isfile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_venv_file
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def find_venv_file(folder):
"""
Find the .venv file. If necessary, go up to the parent folders.
"""
venv_file = Path(folder, VENV_FILE)
while not (venv_file.isfile() or folder == "/"):
folder = folder.parent
venv_file = Path(folder, VENV_FILE)
#
if venv_file.isfile():
if DEBUG:
print("# venv file: {f}".format(f=venv_file), file=sys.stderr)
return venv_file
# else
print("Error: {f} file is missing.".format(f=VENV_FILE), file=sys.stderr)
sys.exit(1)
示例2: main
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def main():
"""
Controller.
"""
args = sys.argv[1:]
if len(args) == 0:
print_usage()
sys.exit(0)
args = check_args(args)
prg = args[0] # script in venv
args = args[1:] # arguments of the script in venv
p = Path(prg).absolute()
venv_file = find_venv_file(p.parent)
venv_dir = Path(venv_file.read_file().strip())
# .venv can also contain a relative path
if not venv_dir.isabsolute():
venv_dir = Path(venv_file.parent, venv_dir).norm()
if not venv_dir.isdir():
print("Error: {vd} is not a directory.".format(vd=venv_dir), file=sys.stderr)
sys.exit(1)
#
python_path = Path(venv_dir, "bin/python")
if not python_path.isfile():
print("Error: {pp} is missing.".format(pp=python_path), file=sys.stderr)
sys.exit(1)
if DEBUG:
print("# venv dir: {d}".format(d=venv_dir), file=sys.stderr)
my_call(python_path, prg, args)
示例3: find_json
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def find_json(dname):
p = Path(dname, "firefox")
with ChDir(p):
profile = glob("*.default")[0]
p = Path(p, profile)
p = Path(p, "jetpack", "[email protected]")
p = Path(p, "simple-storage", "store.json")
assert p.isfile()
return p
示例4: process
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def process(appname):
appdir = Path(appname)
if not appdir.isdir():
print("Error: there is no app called {0}.".format(appdir))
sys.exit(1)
# else
static = Path(appname, 'static', appname)
static.mkdir(True)
templates = Path(appname, 'templates', appname)
templates.mkdir(True)
urls = Path(appname, 'urls.py')
if not urls.isfile():
urls.write_file(urls_py)
示例5: ReleaseUnpackerRarFile
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
class ReleaseUnpackerRarFile(object):
def __init__(self, rar_file_path):
self.rar_file_path = Path(rar_file_path)
if (not self.rar_file_path.exists() or not self.rar_file_path.isfile()
or not self.rar_file_path.ext == '.rar'):
raise ReleaseUnpackerRarFileError('Invalid RAR file {}'.format(
self. rar_file_path))
self.rar_file_path_abs = self.rar_file_path.absolute()
self.rar_file = rarfile.RarFile(self.rar_file_path)
def __repr__(self):
return '<ReleaseUnpackerRarFile: {}>'.format(self.rar_file_path_abs)
@lazy
def name(self):
if self.subs_dir:
name = self.rar_file_path.parent.parent.name
else:
name = self.rar_file_path.parent.name
return str(name)
@lazy
def subs_dir(self):
if self.rar_file_path.parent.name.lower() in ('subs', 'sub'):
return True
else:
return False
@lazy
def file_list(self):
files = []
for file in self.rar_file.infolist():
files.append({'name': Path(file.filename), 'size': file.file_size})
return files
def set_mtime(self):
with file(self.extracted_file_path, 'a'):
os.utime(self.extracted_file_path, None)
def extract_file(self, file_name, unpack_dir):
self.rar_file.extract(file_name, path=unpack_dir)
self.extracted_file_path = Path(unpack_dir, file_name)
# Set the mtime to current time
self.set_mtime()
return self.extracted_file_path
示例6: deploy
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def deploy(request, project_id):
"""
Deploy project to specific location
"""
try:
project = Project.objects.get(pk=project_id)
except:
return HttpResponse("Project not found");
path = Path(project.path)
if path.isfile():
return HttpResponse("Expected deploy path to be a directory");
# add tasks to messagequeue server
tasks.deploy.delay(model_to_dict(project))
return HttpResponse("Task dispatched, your project should be deployed shortly.");
示例7: append
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def append(self, key):
key_path = Path(key)
if key_path.isfile():
with open(str(key_path)) as f:
key = f.read()
if key in self:
return
directory = Path(self.user.path, 'keydir', self.user.name,
hashlib.md5(key.strip().split()[1]).hexdigest())
directory.mkdir(parents=True)
key_file = Path(directory, "%s.pub" % self.user.name)
if key_file.exists() and key_file.read_file() == key:
return
key_file.write_file(key)
self.user.git.commit(['keydir'],
'Added new key for user %s' % self.user.name)
super(ListKeys, self).append(key)
示例8: content
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def content(request=None):
base = Path(current_app.config.get('INUPYPI_REPO',
Path('.', 'packages')))
if request:
repo = Path(base, request)
else:
repo = base
try:
repo = repo.absolute()
base = base.absolute()
if not repo.exists():
if base == repo:
raise InuPyPIMissingRepoPath
# sets the request to lowercase and compares it with
# the existing items in the repository in lowercase
repo = search_path(repo, base)
if not repo:
raise InuPyPI404Exception
if repo.isdir():
return Dirs(repo)
if repo.isfile():
return repo
except InuPyPIMissingRepoPath:
abort(500, 'Missing repository or package path!')
except InuPyPI404Exception:
abort(404, 'Path or File could not be found!')
except:
abort(500, 'Internal Server Error!')
return repo
示例9: print
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
print(Path("$HOME").expand_vars()) # Expands system variables
print(Path("/home/luke/..").norm()) # Expands .. and . notation
print(Path("$HOME/..").expand()) # Expands system variables, ~ and also ..
# Expands system variable and ~. Will also normalise the path ( remove redundant
# .. . incorrect slashes and correct capitalisation on case sensitive file systems. Calls os.path.normpath
# File Attributes and permissions
print("\n*** File Attributes and permissions")
# noinspection PyArgumentList
print(here.atime()) # Last access time; seconds past epcoh
# noinspection PyArgumentList
print(here.ctime()) # Last permission or ownership modification; windows is creation time;
# noinspection PyArgumentList
print(here.isfile()) # Is a file; symbolic links are followed.
print(here.isdir()) # Is a directory; symbolic links are followed.
# noinspection PyArgumentList
print(here.islink()) # Is a symbolic link
# noinspection PyArgumentList
print(here.ismount()) # Is a mount point; ie the parent is on a different device.
# noinspection PyArgumentList
print(here.exists()) # File exists; symbolic links are followed.
# noinspection PyArgumentList
print(here.lexists()) # Same as exists but symbolic links are not followed.
# noinspection PyArgumentList
print(here.size()) # File size in bytes.
print(Path("/foo").isabsolute()) # Is absolute and not relative path
# Epoch?
print("\n*** gmtime")
示例10: is_a_command
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def is_a_command(self, request):
"""
is the request a command ?
trying to recognize a command
and keep command and args to avoid double parsing
"""
request = request.lower()
if request.endswith('?'):
request = request[:-1]
is_command = False
# @todo meet a problem when command has two or more words,
# need to check this also
command_list = request.split()
path = Path(
ROBOT_DIR.child('core', 'brain') + '/'
+ '/'.join(request.split()) + '/reaction.py')
if not is_command and len(command_list) > 1:
logger.info('Command %s consist of %d words' % (
request, len(command_list)))
self._cmd_args = command_list
self._cmd_path = []
# this method will try to find first full cmd
# after that one level up
if path.isfile():
is_command = True
logger.info('Reaction file has been found at %s', self._cmd_path)
logger.info('Request is command .. continue')
# set something like ['ping', 'my', 'sites']
self._cmd_path = self._cmd_args
# last added
# user defined script
if path.isfile() and not is_command:
logger.info('User defined reaction found at %s', path)
is_command = True
# sets something like ['ping', 'my', 'sites']
#self._cmd_path = path.relative().parent.split('/')
self._cmd_path = command_list
self._cmd_args = command_list
logger.info('cmd_path %s', self._cmd_path)
#
# First check for simple(one word) commands
# why ?
# moved to second position
# example : I want to know : who is looking for a thing in internet
# instead of who is Chuck Norris
if is_command is False:
logger.info('Check for embedded..')
if request.startswith(settings.EMBEDDED_COMMANDS):
logger.info('Embedded command detected %s!' % self._cmd_path)
for c in settings.EMBEDDED_COMMANDS:
if request.startswith(c):
break
self._cmd_path = c.split()
self._cmd_args = request.replace(c, '').split()
is_command = True
if is_command is False:
self._request_processed = False
self._continue_dialog = True
logger.info('Request is not a command .. continue')
return is_command
示例11: get_file
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isfile [as 别名]
def get_file(eggbasket, package, filename):
package_file = Path(get_package_path(eggbasket), package, filename)
if package_file.exists() and package_file.isfile():
return package_file
return False