本文整理汇总了Python中moments.path.Path.load方法的典型用法代码示例。如果您正苦于以下问题:Python Path.load方法的具体用法?Python Path.load怎么用?Python Path.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moments.path.Path
的用法示例。
在下文中一共展示了Path.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: diff_files
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def diff_files(fname, path1, path2, indent, diff_system=False):
#until we prove otherwise, we'll assume they're different
is_difference = True
p1 = Path(path1)
n1 = p1.load()
#n1 = make_node(path1)
p2 = Path(path2)
n2 = p2.load()
#n2 = make_node(path2)
if n1.size == n2.size:
#probably pretty safe to assume that they are equal
#print " %s - BOTH, SAME SIZE" % phraseUnicode2ASCII(fname)
#print "EQUAL sizes: %s %s" % (n1.size, n2.size)
is_difference = False
#could do additional checks if desired
#enabling another diff level will take longer, but will be more accurate:
f_a = file(path1)
f_b = file(path2)
a = f_a.readlines()
b = f_b.readlines()
diff = unified_diff(a, b)
for d in diff:
is_difference = True
#print d
#this will signal which files have differences:
if is_difference:
print(" %s - BOTH, DIFFERENT CONTENT" % fname.translate(unaccented_map()))
#could move it somewhere else:
#os.rename(path1, os.path.join(d1, "dupes", fname))
#os.rename(path2, os.path.join(d2, "merged", fname))
else:
#print " %s - BOTH, DIFFERENT SIZE" % phraseUnicode2ASCII(fname)
print(" %s - BOTH, DIFFERENT SIZE" % fname.translate(unaccented_map()))
if diff_system:
print("diffing: %s %s\n" % (path1, path2))
try:
#diff_system( phraseUnicode2ASCII(path1),
# phraseUnicode2ASCII(path2) )
#diff_playlists(n1, n2)
diff_system( path1.translate(unaccented_map()),
path2.translate(unaccented_map()) )
except:
print("Unable to diff.")
return is_difference
示例2: collection_zip
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def collection_zip(collection_name=None, content_name=None):
"""
"""
result = ''
content = None
if collection_name:
summary = get_summary(collection_name)
content = summary.load_content(content_name)
if content:
sources = []
content.zips = find_zips(content.path)
import zipfile
for zipf in content.zips:
zipp = Path(zipf)
#print zipp.name
zip_root = os.path.join(content.path, zipp.name)
if not os.path.exists(zip_root):
os.makedirs(zip_root)
zfile = zipfile.ZipFile(zipf)
for name in zfile.namelist():
(dirname, filename) = os.path.split(name)
#print "Decompressing " + filename + " on " + dirname
dest_dir = os.path.join(zip_root, dirname)
if not dest_dir in sources:
sources.append(dest_dir)
print("Decompressing " + filename + " to " + dest_dir + "<br>")
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
dest = os.path.join(dest_dir, name)
if not os.path.exists(dest):
fd = open(dest, "w")
fd.write(zfile.read(name))
fd.close()
dpath = Path(dest)
print("making thumb")
img = dpath.load()
img.make_thumbs(['small'], save_original=False)
zips = []
for source in sources:
spath = Path(source, relative_prefix=path_root)
sdir = spath.load()
zips.append(sdir.contents)
print(source)
#return template('simple', body=result, title="unzip!")
return template('zip', zips=zips)
示例3: path
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def path(relative=''):
"""
serve a static file
this also allows pose to function as a customizable file system browser
be careful with what you set path_root to
if the machine you run this on has sensitive information
and is connected to a public network
"""
global path_root
if re.match('~', relative):
relative = os.path.expanduser(relative)
## else:
## relative = os.path.join('/', relative)
## full = os.path.abspath(relative)
## print full
full_path = os.path.join(path_root, relative)
path = Path(full_path, relative_prefix=path_root)
if path.type() == "Directory":
node = path.load()
#will depend what we want to sort by here:
node.sort_by_path()
#node.sort_by_date()
return template('directory', path=path, contents=node.contents)
else:
#this is equivalent to a view...
#indicate it in the log:
#path.log_action()
return static_file(relative, root=path_root)
示例4: add_new
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def add_new(source_list, source_dir, destination=None):
#ignores = ["classics", "misc", "other", "youtube-dl", "playlists"]
ignores = ["playlists"]
m3u = M3U(source_list)
if os.path.isdir(source_dir):
source_dir_path = Path(source_dir)
subdirs = source_dir_path.load().directories
#subdirs = os.listdir(source_dir)
for subdir in subdirs:
print("")
if check_ignore(str(subdir), ignores):
print("SKIP (IGNORES): %s" % subdir)
else:
print("SUBDIR: %s" % subdir)
scan_dir(m3u, subdir)
scan_dir(m3u, source_dir)
else:
print("NOT A DIRECTORY: %s" % source_dir)
print("")
print("")
#for item in m3u:
# print item
if destination is None:
source_list_path = Path(source_list)
dest_name = Timestamp().compact(accuracy="day") + "-videos.m3u"
destination = os.path.join(str(source_list_path.parent()), dest_name)
print("Saving to: %s" % destination)
m3u.save(destination)
示例5: rotate_image
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def rotate_image(source, degrees):
if os.path.exists(source):
p = Path(source)
assert p.type() == "Image"
i = p.load()
print("Rotating %s by %s degrees" % (source, degrees))
i.rotate(degrees)
#i.auto_rotate()
else:
print("Couldn't find path: %s" % source)
exit()
示例6: find_jsons
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def find_jsons(item, limit_by_name=False, debug=False):
"""
foundation for find_json
but this returns all matches (based on parameters)
"""
if re.search('.*\.json$', item):
if debug:
#print "find_and_load_json: item is a json string: %s" % item
logging.debug("find_json: item is a json string: %s" % item)
return [item]
else:
parent = ''
name = ''
p = Path(item)
if p.type() == "Directory":
#item must be a directory... just look here
parent = p
d = p.load()
else:
name = to_tag(p.name)
#must be some other file type... load the parent directory:
parent = p.parent()
d = parent.load()
if debug:
print("%s not a directory, using: %s" % (item, parent))
matches = []
for j in d.files:
#if debug:
# print "Checking: %s" % j
if re.search('\.json$', str(j)):
if debug:
print("matched json: %s" % j)
match = os.path.join(str(parent), str(j))
#this should allow us to hone in on one
#if there is more than one media file in a directory
if name and limit_by_name:
if re.search(name, str(j)):
matches.append(match)
else:
if debug:
print("could not find %s in %s" % (name, str(j)))
else:
matches.append(match)
if debug:
print("Found the following: %s" % matches)
return matches
示例7: extract_zips
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def extract_zips(source, make_subdir=True):
"""
take a source
make sure it has not been extracted already
unzip the file
"""
path = Path(source)
source = path.load()
#print source.directories
for d in source.directories:
#print d.path
dpath = d.load()
for f in dpath.files:
#must have a zip file
if re.search('.zip', f.path) and f.extension == '.zip':
if make_subdir:
# this uses the zip's filename for the directory
#destination = os.path.join(str(f.parent()), str(f.name))
# sometimes the zip is not descriptive...
# better to use the parent directory name
destination = os.path.join(str(f.parent()), str(f.parent().name))
dest_path = Path(destination)
else:
#otherwise, just put them in the main directory
#dest_path = Path(destination)
destination = str(f.parent())
dest_path = f.parent()
#TODO:
#create a file to indicate the extract already happen
#to skip on future runs
#if not alredy_extracted.exists():
#if not dest_path.exists():
#else:
# print "already extracted: %s" % f.path
#print "extracting: %s" % f.path
#this extracts to the dpath directory, not a new
#subdirectory with the same name (like we are checking for)
#good enough for this round, but may want to improve on that
#command = "unzip %s -d %s" % (f.path, d.path)
#command = "unzip %s -d %s" % (f.path, destination)
#adding -fo option -f: freshen -o: overwrite without prompting
command = "unzip -o %s -d %s" % (f.path, destination)
print("not found, unzipping: %s" % command)
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output = process.communicate()[0]
if output:
print(output)
示例8: size_of_list
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def size_of_list(source, media_root=None, ignores=['/c/',]):
"""
ignores are used to distinguish actual media from markers
"""
items = []
if re.search('.m3u', source):
items = M3U(source)
elif re.search('.json', source):
loaded = load_json(source)
#see if we have a dictionary or a list:
if isinstance(loaded, list):
#already have a list
#clean it up
for item in loaded:
#these are usually content .json files:
content = Content(item[0])
#print content.media
items.append(content.media[-1][0])
elif isinstance(loaded, dict):
#walk the tree to load each item individually
#could call size_of_list() recursively
pass
total_size = 0
total_items = 0
#seconds?
total_length = 0
for item in items:
check_item = False
if media_root and re.match(media_root, item):
check_item = True
#elif not re.match(ignore, item):
elif not check_ignore(item, ignores):
check_item = True
if check_item:
p = Path(item)
f = p.load()
total_size += f.check_size()
results = get_media_properties(item)
print(results)
total_length += results[1]
total_items += 1
#print item
print("found %s matching items" % total_items)
return total_size, total_length, total_items
示例9: group_by_day
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def group_by_day(path, dest_prefix=None, tags=[]):
"""
look at a directory, and group all files by the day they were created
run through a supplied directory's files
create sub-directories that correspond to the day of the files' timestamps
move the files to their corresponding day subdirectory
in the new_dir destination
"""
if dest_prefix is None:
dest_prefix = path
p = Path(path)
d = p.load()
#d = make_node(path)
d.sort_by_date()
dates = []
destinations = []
last_date = None
cur_batch = []
print("%s Files found in %s" % (len(d.files), path))
for fpath in d.files:
#print f.name
f = fpath.load()
if f.date() != last_date:
#check if we need to move the previous day's files:
print("New day: %s (previously: %s)" % (f.date(), last_date))
if cur_batch:
dest = process_batch(cur_batch, last_date, dest_prefix, tags)
destinations.append(dest)
cur_batch = [ f ]
last_date = f.date()
else:
cur_batch.append(f)
#get the last one:
if cur_batch:
dest = process_batch(cur_batch, last_date, dest_prefix, tags)
if not dest in destinations:
destinations.append( dest )
#if we need to do something else to the new directories
#we have them all collected in destinations list
return destinations
示例10: find_media
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def find_media(item):
"""
using this in content.import_content to check for time based media
(videos or sounds)
"""
p = Path(item)
if p.type() == "Directory":
root = p.load()
else:
parent = p.parent()
root = parent.load()
matches = []
#now root is a directory...
#use that to help find media
root.scan_filetypes()
matches.extend(root.sounds)
matches.extend(root.movies)
return matches
示例11: reset_images
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def reset_images(source):
print("Looking in: %s" % source)
path = Path(source)
if path.exists() and path.type() == "Directory":
d = path.load()
d.scan_filetypes()
#print d.images
for image in d.images:
#print image
i = image.load()
print("old: %s" % i.datetime())
i.datetime_exif()
i = image.load()
print("new: %s" % i.datetime())
print()
#print d.directories
for sub_d in d.directories:
reset_images(sub_d)
else:
print("Couldn't find path: %s" % source)
exit()
示例12: main
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def main():
#requires that at least one argument is passed in to the script itself
#(through sys.argv)
if len(sys.argv) > 1:
helps = ['--help', 'help', '-h']
for i in helps:
if i in sys.argv:
usage()
exit()
#skip the first argument (filename):
for arg in sys.argv[1:]:
print(arg)
path = Path(arg)
source = path.load()
#print(source.directories)
for d in source.directories:
print("looking in: ", d)
extract_zips(d)
else:
usage()
exit()
示例13: find_and_load_json
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def find_and_load_json(item, debug=False):
"""
look in the same directory as item for a json file
if found, load it and return the loaded object
otherwise return None
also [2013.07.03 10:30:19]
deprecated:
probably better to find_json()
then load_json()
"""
if re.search('.*\.json', item):
if debug:
#print "find_and_load_json: item is a json string: %s" % item
logging.debug("find_and_load_json: item is a json string: %s" % item)
loaded = load_json(item)
else:
p = Path(item)
if p.type() == "Directory":
parent = p
d = p.load()
else:
parent = p.parent()
d = parent.load()
loaded = None
for j in d.files:
if re.search('.*\.json', str(j)):
logging.debug("find_and_load_json: loading from: %s" % j)
#print "find_and_load_json: loading from: %s" % j
match = os.path.join(str(parent), str(j))
loaded = load_json(match)
#jso = file(os.path.join(str(parent), str(j)))
#loaded = json.loads(jso.read())
return loaded
示例14: check_dates
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def check_dates(sources):
"""
go through all sources and look for the days covered
this is useful to check for media from
devices that don't keep an accurate clock
related to group_by_day, but not processing any batches here
"""
dates = []
for source in sources:
p = Path(source)
if p.exists():
d = p.load()
#print(d)
#print(type(d))
d.sort_by_date()
for fpath in d.files:
#print f.name
f = fpath.load()
if not f.date() in dates:
dates.append(f.date())
return dates
示例15: benchmark
# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import load [as 别名]
def benchmark(source):
"""
run through all tests, timing along the way
timeit gets mentioned many times:
http://docs.python.org/3.4/library/timeit.html
"""
print("Testing moments: ")
start_time = time.time()
print("making path:")
step_time = time.time()
pic = Path(source)
print(time.time() - step_time, "seconds")
print("")
print("loading path:")
step_time = time.time()
img = pic.load()
print(time.time() - step_time, "seconds")
print("")
#13.3232491016 seconds:
## print "make thumbs: (all)"
## step_time = time.time()
## img.make_thumbs()
## print time.time() - step_time, "seconds"
## print ""
## print "removing thumbs: (all)"
## step_time = time.time()
## shutil.rmtree("sized")
## print time.time() - step_time, "seconds"
## print ""
#3.2377550602 seconds:
## print "make thumbs: (tiny)"
## step_time = time.time()
## img.make_thumbs(["tiny"])
## print time.time() - step_time, "seconds"
## print ""
## print "removing thumbs: (tiny)"
## step_time = time.time()
## shutil.rmtree("sized")
## print time.time() - step_time, "seconds"
## print ""
#now break it down to steps:
#0.000612020492554 seconds
## print "make thumbs dirs()"
## step_time = time.time()
## img.make_thumb_dirs()
## print time.time() - step_time, "seconds"
## print ""
## print "removing thumbs dirs"
## step_time = time.time()
## shutil.rmtree("sized")
## print time.time() - step_time, "seconds"
## print ""
#0.00586199760437 seconds
print("Open image with PIL: ")
step_time = time.time()
image = PILImage.open(source)
print(time.time() - step_time, "seconds")
print("")
print("show sizes: ")
step_time = time.time()
print(image.size)
print(time.time() - step_time, "seconds")
print("")
#0.56491112709 seconds
print("Copy image buffer in PIL: ")
step_time = time.time()
square = image.copy()
print(time.time() - step_time, "seconds")
print("")
print("resize max: ")
step_time = time.time()
pre_crop = resize_max(400, image.size[0], image.size[1])
print(pre_crop)
print(time.time() - step_time, "seconds")
print("")
#0.108213186264 seconds
print("Square image (includes copy)")
step_time = time.time()
square = img._square_image(square)
print(time.time() - step_time, "seconds")
print("")
#xl = 2880
#.........这里部分代码省略.........