本文整理汇总了Python中os.R_OK属性的典型用法代码示例。如果您正苦于以下问题:Python os.R_OK属性的具体用法?Python os.R_OK怎么用?Python os.R_OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类os
的用法示例。
在下文中一共展示了os.R_OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_floppy_image
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def create_floppy_image(vlock_filename, floppy_image):
""" Creates the floppy image used to install the vlock file
"""
# Delete any existing image to start clean
if os.access(floppy_image, os.R_OK):
os.unlink(floppy_image)
subprocess.check_call("mkfs.vfat -C {} 1440".format(floppy_image),
shell=True)
floppy_mnt = "/tmp/mnt-dashboard"
os.mkdir(floppy_mnt)
subprocess.check_call("mount -o loop {} {}".format(floppy_image,
floppy_mnt),
shell=True)
shutil.copy(vlock_filename, os.path.join(floppy_mnt, "versionlock.list"))
subprocess.check_call("umount {}".format(floppy_mnt), shell=True)
os.rmdir(floppy_mnt)
示例2: extract_file_properties
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def extract_file_properties(self):
"""Extracts file size,
nb of dirs and classes in smali dir"""
if self.verbose:
print("------------- Extracting file properties")
self.properties.file_size = os.stat(self.absolute_filename).st_size
if self.properties.file_size < 70000:
self.properties.file_small = True
smali_dir = os.path.join(self.outdir, "smali")
if os.access(smali_dir, os.R_OK):
self.properties.file_nb_dir, self.properties.file_nb_classes = droidutil.count_filedirs(smali_dir)
if self.verbose:
print( "Filesize: %d" % (self.properties.file_size))
print( "Is Small: %d" % (self.properties.file_small))
print( "Nb Class: %d" % (self.properties.file_nb_classes))
print( "Nb Dir : %d" % (self.properties.file_nb_dir))
示例3: extract_kit_properties
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def extract_kit_properties(self):
"""
Detects which kits are present in the sample currently analyzed
Returns something like: ['apperhand', 'jackson', 'applovin', 'leadbolt', 'airpush']
"""
list = []
if self.properties.filetype == droidutil.APK or self.properties.filetype == droidutil.DEX:
smali_dir = os.path.join(self.outdir, "smali")
if os.access(smali_dir, os.R_OK):
for section in self.properties.kitsconfig.get_sections():
pattern_list = self.properties.kitsconfig.get_pattern(section).split('|')
for pattern in pattern_list:
if os.access(os.path.join(smali_dir, pattern), os.R_OK):
if self.verbose:
print("kits[%s] = True (detected pattern: %s)" % (section, pattern))
list.append(section)
self.properties.kits[ section ] = True
break # break one level
return list
示例4: opt_exampleimg
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def opt_exampleimg(f):
def callback(ctx, param, value):
# Check if file qualifies alone
if os.path.isfile(value):
_value = value
else:
# Check if path relative to root qualifies
_value = os.path.join(ctx.params['root'], value)
if not os.path.isfile(_value):
raise click.BadParameter('Cannot find example image '
'"{f}"'.format(f=value))
if not os.access(_value, os.R_OK):
raise click.BadParameter('Found example image but cannot '
'read from "{f}"'.format(f=_value))
return os.path.abspath(_value)
return click.option('--image', '-i',
default='example_img',
metavar='<image>',
show_default=True,
help='Example timeseries image',
callback=callback)(f)
示例5: opt_resultdir
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def opt_resultdir(f):
def callback(ctx, param, value):
# Check if path qualifies alone
if os.path.isdir(value):
_value = value
else:
# Check if path relative to root qualifies
_value = os.path.join(ctx.params['root'], value)
if not os.path.isdir(_value):
raise click.BadParameter('Cannot find result directory '
'"{d}"'.format(d=value))
if not os.access(_value, os.R_OK):
raise click.BadParameter('Found result directory but cannot '
'read from "{d}"'.format(d=_value))
return os.path.abspath(_value)
return click.option('--result', '-r',
default='YATSM',
metavar='<directory>',
show_default=True,
help='Directory of results',
callback=callback)(f)
# CALLBACKS
示例6: read_device_config
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def read_device_config(self):
for config_path in self.DEVICE_CONFIG_PATHS:
config_file = os.path.join(config_path, self.DEVICE_CONFIG)
if os.path.isfile(config_file) and \
os.access(config_file, os.R_OK):
with open(config_file, 'r') as h:
json_text = h.read().decode(self.ENCODING)
logger.debug('Device configuration:\n{}'.format(json_text))
json_text = json_text.replace('\n', '')
try:
device_config = json.loads(json_text)
logger.info(
'Loaded device config "{}"'.format(config_file))
return device_config
except ValueError:
logger.error(
'Unable to parse "{}"! '
'Check the file for syntax errors ...'.format(
config_file))
return None
示例7: getFileDisassembled
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def getFileDisassembled(path, optimization):
"""Dsassembles a file"""
if not os.path.exists(path):
raise Exception("Cannot find " + path + " to disassemble")
if not os.access(path, os.R_OK):
raise Exception("No read permissions for " + path)
tempPycFile = makeTempFile(suffix='.pyc')
try:
py_compile.compile(path, tempPycFile,
doraise=True, optimize=optimization)
except Exception as exc:
safeUnlink(tempPycFile)
raise Exception("Cannot disassemble file " + path + ': ' + str(exc))
try:
result = getCompiledfileDisassembled(tempPycFile, path, optimization)
except:
safeUnlink(tempPycFile)
raise
safeUnlink(tempPycFile)
return result
示例8: do_generate_fonts
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def do_generate_fonts(template_file, font_basename, pairs, reuse=0, verbosity=1):
out_woff = font_basename + '.woff'
if reuse > 1 and os.path.isfile(out_woff) and os.access(out_woff, os.R_OK):
if verbosity:
print('Reusing ' + out_woff)
return
out_ttx = font_basename + '.ttx'
if reuse == 0:
add_svg_glyphs.add_image_glyphs(template_file, out_ttx, pairs, verbosity=verbosity)
elif verbosity:
print('Reusing ' + out_ttx)
quiet=verbosity < 2
font = ttx.TTFont(flavor='woff', quiet=quiet)
font.importXML(out_ttx, quiet=quiet)
font.save(out_woff)
if verbosity:
print('Wrote ' + out_woff)
示例9: clip_arg
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def clip_arg(clip):
(file_root, file_ext) = os.path.splitext(clip)
if file_ext == '.y4m':
width = int(subprocess.check_output(["mediainfo", "--Inform=Video;%Width%", clip]))
height = int(subprocess.check_output(["mediainfo", "--Inform=Video;%Height%", clip]))
fps = float(subprocess.check_output(["mediainfo", "--Inform=Video;%FrameRate%", clip]))
return {'input_file': clip, 'height': height, 'width': width, 'fps': fps, 'file_type': 'y4m'}
# Make sure YUV files are correctly formatted + look readable before actually
# running the script on them.
clip_match = yuv_clip_pattern.match(clip)
if not clip_match:
raise argparse.ArgumentTypeError("Argument '%s' doesn't match input format.\n" % clip)
input_file = clip_match.group(1)
if not os.path.isfile(input_file) or not os.access(input_file, os.R_OK):
raise argparse.ArgumentTypeError("'%s' is either not a file or cannot be opened for reading.\n" % input_file)
return {'input_file': clip_match.group(1), 'width': int(clip_match.group(2)), 'height': int(clip_match.group(3)), 'fps' : float(clip_match.group(4)), 'file_type': 'yuv'}
示例10: test_connections
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def test_connections(self):
"""
Checks for our control port in the stem.util.proc.connections output if
we have one.
"""
runner = test.runner.get_runner()
if test.runner.Torrc.PORT not in runner.get_options():
self.skiTestp('(no control port)')
return
elif not os.access('/proc/net/tcp', os.R_OK) or not os.access('/proc/net/udp', os.R_OK):
self.skipTest('(proc lacks read permissions)')
# making a controller connection so that we have something to query for
with runner.get_tor_socket():
tor_pid = test.runner.get_runner().get_pid()
for conn in proc.connections(tor_pid):
if ('127.0.0.1', test.runner.CONTROL_PORT) == conn[:2]:
return
self.fail()
示例11: testCollectionAction
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def testCollectionAction(self):
collection, final_path = self._make_collection()
with collection.create_temp_file():
self.assertFalse(os.access(final_path, os.R_OK))
self.assertTrue(os.access(collection._filename, os.R_OK))
# Insert some data.
collection.insert(c1=5, c2="foobar", c3=1.1)
# Make sure the tempfile is removed and the final_path exists.
self.assertFalse(os.access(collection._filename, os.R_OK))
self.assertTrue(os.access(final_path, os.R_OK))
# Re-open the collection for reading.
with result_collections.GenericSQLiteCollection.load_from_location(
collection.location, session=self.session) as read_collection:
# This should reuse the final_path saving a local copy.
self.assertEqual(read_collection._filename, final_path)
# Query the collection.
self.assertEqual([tuple(x) for x in read_collection.query()],
[(5, "foobar", 1.1)])
示例12: GetCacheDir
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def GetCacheDir(session):
"""Returns the path of a usable cache directory."""
cache_dir = session.GetParameter("cache_dir")
if cache_dir == None:
return cache_dir
cache_dir = os.path.expandvars(cache_dir)
if not cache_dir:
raise io_manager.IOManagerError(
"Local profile cache is not configured - "
"add a cache_dir parameter to ~/.rekallrc.")
# Cache dir may be specified relative to the home directory.
cache_dir = os.path.join(config.GetHomeDir(session), cache_dir)
if not os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
try:
os.makedirs(cache_dir)
except (IOError, OSError):
raise io_manager.IOManagerError(
"Unable to create or access cache directory %s" % cache_dir)
return cache_dir
示例13: try_to_find_osquery
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def try_to_find_osquery(self):
extention = ""
if platform.system() == "Windows":
extention = ".exe"
try:
return resources.get_resource("osqueryi" + extention)
except IOError as e:
# Maybe it is installed on the system.
if platform.system() == "Windows":
result = r"c:\ProgramData\osquery\osqueryi.exe"
if os.access(result, os.R_OK):
return result
else:
# Try to find it somewhere on the system.
return spawn.find_executable("osqueryi")
raise e
示例14: read_vm_image_type
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def read_vm_image_type(path):
if not os.path.isfile(path):
raise PcoccError("{} is not an image file".format(path))
if not os.access(path, os.R_OK):
raise PcoccError("{} is not readable".format(path))
try:
jsdata = subprocess.check_output(["qemu-img", "info","--output=json", path])
except subprocess.CalledProcessError:
return None
try:
data = json.loads(jsdata)
except Exception:
return None
return data.get("format", None)
示例15: read_vm_image_backing_file
# 需要导入模块: import os [as 别名]
# 或者: from os import R_OK [as 别名]
def read_vm_image_backing_file(path, full=False):
if not os.path.isfile(path):
raise PcoccError("{} is not an image file".format(path))
if not os.access(path, os.R_OK):
raise PcoccError("{} is not readable".format(path))
try:
jsdata = subprocess.check_output(["qemu-img", "info","--output=json", path])
except subprocess.CalledProcessError:
return None
try:
data = json.loads(jsdata)
except Exception:
return None
res = None
if full:
res = data.get("full-backing-filename", None)
if not res:
res = data.get("backing-filename", None)
return res