本文整理汇总了Python中pyasm.common.Common.which方法的典型用法代码示例。如果您正苦于以下问题:Python Common.which方法的具体用法?Python Common.which怎么用?Python Common.which使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.common.Common
的用法示例。
在下文中一共展示了Common.which方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_video
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
def _process_video(my, file_name):
ffmpeg = Common.which("ffmpeg")
if not ffmpeg:
return
thumb_web_size = my.get_web_file_size()
thumb_icon_size = (120, 100)
exts = File.get_extensions(file_name)
base, ext = os.path.splitext(file_name)
icon_file_name = "%s_icon.png" % base
web_file_name = "%s_web.jpg" % base
tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name)
tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name)
#cmd = '''"%s" -i "%s" -r 1 -ss 00:00:01 -t 00:00:01 -s %sx%s -f image2 "%s"''' % (ffmpeg, my.file_path, thumb_web_size[0], thumb_web_size[1], tmp_web_path)
#os.system(cmd)
import subprocess
try:
subprocess.call([ffmpeg, '-i', my.file_path, "-y", "-ss", "00:00:01","-t","00:00:01",\
"-s","%sx%s"%(thumb_web_size[0], thumb_web_size[1]), "-f","image2", tmp_web_path])
my.web_path = tmp_web_path
except:
pass
try:
subprocess.call([ffmpeg, '-i', my.file_path, "-y", "-ss", "00:00:01","-t","00:00:01",\
"-s","%sx%s"%(thumb_icon_size[0], thumb_icon_size[1]), "-f","image2", tmp_icon_path])
my.icon_path = tmp_icon_path
except:
pass
示例2: _process_pdf
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
def _process_pdf(my, file_name):
base, ext = os.path.splitext(file_name)
# naming convetion should take care of inserting a suffix like icon, web
# but these paths need a unique name
icon_file_name = base + "_icon.png"
tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name)
thumb_web_size = my.get_web_file_size()
web_file_name = base + "_web.png"
tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name)
if sys.platform == 'darwin':
return
else:
if not Common.which(convert_exe):
return
try:
my.file_path = my.file_path.encode('utf-8')
import shlex, subprocess
subprocess.call([convert_exe, '-geometry','80','-raise','2x2','%s[0]'%my.file_path,\
"%s"%tmp_icon_path])
subprocess.call([convert_exe, '-geometry','%sx%s'%(thumb_web_size[0], \
thumb_web_size[1]),'-raise','2x2','%s[0]' %my.file_path, "%s"%tmp_web_path])
except Exception, e:
print "Error extracting from pdf [%s]" % e
return
示例3: _process_video
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
def _process_video(my, file_name):
ffmpeg = Common.which("ffmpeg")
if not ffmpeg:
return
thumb_web_size = my.get_web_file_size()
thumb_icon_size = (120, 100)
exts = File.get_extensions(file_name)
base, ext = os.path.splitext(file_name)
icon_file_name = "%s_icon.png" % base
web_file_name = "%s_web.jpg" % base
tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name)
tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name)
#cmd = '''"%s" -i "%s" -r 1 -ss 00:00:01 -t 1 -s %sx%s -vframes 1 "%s"''' % (ffmpeg, my.file_path, thumb_web_size[0], thumb_web_size[1], tmp_web_path)
#os.system(cmd)
import subprocess
try:
subprocess.call([ffmpeg, '-i', my.file_path, "-y", "-ss", "00:00:01","-t","1",\
"-s","%sx%s"%(thumb_web_size[0], thumb_web_size[1]),"-vframes","1","-f","image2", tmp_web_path])
if os.path.exists(tmp_web_path):
my.web_path = tmp_web_path
else:
my.web_path = None
except Exception, e:
Environment.add_warning("Could not process file", \
"%s - %s" % (my.file_path, e.__str__()))
pass
示例4: _process_pdf
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
def _process_pdf(self, file_name):
base, ext = os.path.splitext(file_name)
# naming convetion should take care of inserting a suffix like icon, web
# but these paths need a unique name
icon_file_name = base + "_icon.png"
tmp_icon_path = "%s/%s" % (self.tmp_dir, icon_file_name)
thumb_web_size = self.get_web_file_size()
web_file_name = base + "_web.png"
tmp_web_path = "%s/%s" % (self.tmp_dir, web_file_name)
if sys.platform == 'darwin':
return
else:
if not Common.which(convert_exe):
return
try:
self.file_path = self.file_path.encode('utf-8')
import shlex, subprocess
subprocess.call([convert_exe, '-geometry','80','-raise','2x2','%s[0]'%self.file_path,\
"%s"%tmp_icon_path])
# Shrink image based on web_file_size
# (preserves aspect ratio regardless)
pdf_width = thumb_web_size[0]
if thumb_web_size[1] == -1:
pdf_height = pdf_width*10
else:
pdf_height = thumb_web_size[1]
size = '%sx%s>' % (pdf_width, pdf_height)
subprocess.call([convert_exe, '-geometry', size, '-raise','2x2','%s[0]' %self.file_path, "%s"%tmp_web_path])
except Exception as e:
print("Error extracting from pdf [%s]" % e)
return
# check that it actually got created
if os.path.exists(tmp_icon_path):
self.icon_path = tmp_icon_path
else:
print("Warning: [%s] did not get created from pdf" % tmp_icon_path)
if os.path.exists(tmp_web_path):
self.web_path = tmp_web_path
else:
print("Warning: [%s] did not get created from pdf" % tmp_web_path)
示例5: _process_pdf
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
def _process_pdf(my, file_name):
base, ext = os.path.splitext(file_name)
icon_file_name = base + "_icon.png"
tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name)
if sys.platform == 'darwin':
return
else:
if not Common.which("convert"):
return
try:
my.file_path = my.file_path.encode('utf-8')
import shlex, subprocess
subprocess.call(['convert', '-geometry','80','-raise','2x2','%s[0]'%my.file_path,\
"%s"%tmp_icon_path])
except Exception, e:
print "Error extracting from pdf [%s]" % e
return
示例6: Popen
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
try:
convert_process = Popen(['convert','-version'], stdout=PIPE, stderr=PIPE)
convert_return,convert_err = convert_process.communicate()
if 'ImageMagick' in convert_return:
convert_exe = 'convert'
HAS_IMAGE_MAGICK = True
except:
pass
ffprobe_exe = "ffprobe"
ffmpeg_exe = "ffmpeg"
if os.name == 'nt':
ffprobe_exe = "ffprobe.exe"
ffmpeg_exe = "ffmpeg.exe"
if Common.which(ffprobe_exe):
HAS_FFMPEG = True
else:
HAS_FFMPEG = False
import subprocess
class FileException(TacticException):
pass
class File(SObject):
示例7:
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
import os, sys, re, subprocess
from pyasm.common import Common
from pyasm.biz import File
try:
from PIL import Image
HAS_PIL = True
# Test to see if imaging actually works
import _imaging
except:
HAS_PIL = False
if Common.which("convert"):
HAS_IMAGEMAGICK = True
else:
HAS_IMAGEMAGICK = False
if Common.which("ffprobe"):
HAS_FFMPEG = True
else:
HAS_FFMPEG = False
try:
import exifread
HAS_EXIF = True
except:
HAS_EXIF = False
示例8: sync_paths
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
def sync_paths(my, from_path, to_path):
server = my.kwargs.get("server")
login = my.kwargs.get("login")
paths = my.kwargs.get("paths")
base_dir = my.kwargs.get("base_dir")
paths_sizes = []
if paths:
for path in paths:
full_path = "%s/%s" % (base_dir, path)
print "full_path: ", full_path
size = os.path.getsize(full_path)
paths_sizes.append(size)
if server:
to_path = "%[email protected]%s:%s" % (login, server, to_path)
if os.name == "nt":
# This assumes we are using the cygwin implementation of RSync
if to_path[1] == ":":
# then this is a drive letter
drive_letter = to_path[0]
to_path = "/cygdrive/%s/%s" % (drive_letter, to_path[3:])
if from_path[1] == ":":
# then this is a drive letter
drive_letter = from_path[0]
from_path = "/cygdrive/%s/%s" % (drive_letter, from_path[3:])
to_path = to_path.replace("\\", '/')
from_path = from_path.replace("\\", '/')
rsync = Config.get_value("services", "rsync")
if not rsync:
rsync = Common.which("rsync")
if not rsync:
raise Exception("RSync executable could not be found")
cmd_list = []
cmd_list.append(rsync)
flags = "-az"
cmd_list.append(flags)
if server:
cmd_list.append("-e ssh")
cmd_list.append("-v")
cmd_list.append("--progress")
delete = False
if delete:
cmd_list.append("--delete")
dry_run = my.kwargs.get("dry_run")
if dry_run in [True, 'true']:
cmd_list.append("--dry-run")
relative = True
if relative:
cmd_list.append("--relative")
partial = True
if partial:
cmd_list.append("--partial")
cmd_list.append('%s' % from_path)
cmd_list.append('%s' % to_path)
print "exec: ", " ".join(cmd_list)
program = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
#program.wait()
message_key = my.kwargs.get("message_key")
progress = RSyncProgress(
message_key=message_key,
paths=paths,
paths_sizes=paths_sizes
)
on_update = my.kwargs.get("on_update")
if not on_update:
on_update = progress.on_update
assert(on_update)
on_complete = my.kwargs.get("on_complete")
if not on_complete:
on_complete = progress.on_complete
assert(on_complete)
on_error = my.kwargs.get("on_error")
if not on_error:
on_error = progress.on_error
assert(on_error)
#.........这里部分代码省略.........
示例9: systems
# 需要导入模块: from pyasm.common import Common [as 别名]
# 或者: from pyasm.common.Common import which [as 别名]
convert_exe = 'convert'
HAS_IMAGE_MAGICK = True
except:
pass
else:
# in other systems (e.g. unix) 'convert' is expected to be in PATH
try:
convert_process = Popen(['convert','-version'], stdout=PIPE, stderr=PIPE)
convert_return,convert_err = convert_process.communicate()
if 'ImageMagick' in convert_return:
convert_exe = 'convert'
HAS_IMAGE_MAGICK = True
except:
pass
if Common.which("ffprobe"):
HAS_FFMPEG = True
else:
HAS_FFMPEG = False
import subprocess
class FileException(TacticException):
pass
class File(SObject):
NORMAL_EXT = ['max','ma','xls' ,'xlsx', 'doc', 'docx','txt', 'rtf', 'odt','fla','psd', 'xsi', 'scn', 'hip', 'xml','eani','pdf', 'fbx',