예제 #1
0
파일: publish.py 프로젝트: gacomm/VELVEEVA
def match_zips_to_ctls(zip_path, ctl_path):

	def glob_walk(path, ext):
		matches = []
		for root, dirnames, filenames in os.walk(path):
			for filename in fnmatch.filter(filenames, "*"+ext):
				matches.append(os.path.join(root, filename))
		return matches

	def does_file_exist(fname):
		exists = os.path.exists(fname)
		if not exists: 
			print("%s does not exist!" % fname)
			sys.stdout.flush()
		return exists

	def all_exists(folders):
		return reduce(lambda acc, arg: acc and does_file_exist(arg), folders, True)

	def base_filename(path):
		return os.path.splitext(os.path.split(path)[-1])[0]

	zips = glob_walk(zip_path, '.zip')
	ctls = glob_walk(ctl_path, '.ctl')

	good_zips = [x for x in zips if does_file_exist(x) and is_slide(x)]
	good_ctls = [x for x in ctls if does_file_exist(x)]

	both = list(set([base_filename(x) for x in good_zips]) & set([base_filename(x) for x in good_ctls]))

	return [os.path.join(zip_path, x + ".zip") for x in both], [os.path.join(ctl_path, x + ".ctl") for x in both]
예제 #2
0
파일: ctls.py 프로젝트: gacomm/VELVEEVA
def parseFolder(src, **kwargs):
	actions = kwargs.get("actions", [])
	CUTOFF = kwargs.get("cutoff", float("inf"))
	root = kwargs["root"]
	out = kwargs["out"]

	username = kwargs["username"]
	password = kwargs["password"]
	email = kwargs.get("email", None)

	version = parseCurrentVersion(root)

	source_path = os.path.join(root, src)
	dest_path = os.path.join(root, out)

	if not os.path.exists(dest_path): os.makedirs(dest_path)


	matches = []
	for root, dirnames, filenames in os.walk(source_path):
		for filename in fnmatch.filter(filenames, "*.zip"):
			if is_slide(os.path.join(root,filename)): matches.append(os.path.join(root,filename))


	control_files = [createRecordString(m, version=version, username=username, password=password, email=email) for m in matches]

	for control in control_files:
		with open(os.path.join(dest_path, control['filename']), 'w') as f:
			f.write(control['record'])
예제 #3
0
def find_slides(path, cutoff = 1):
	slides = set([])

	for root, dirnames, filenames in os.walk(path):
		if root.count(os.sep) <= cutoff:
			for filename in filenames:
				parent_path, parent_name = os.path.split(root)
				if is_slide(filename): slides.add(parent_name)

	return list(slides)
예제 #4
0
파일: prefix.py 프로젝트: iroc7/VELVEEVA
def find_slides(path, cutoff=1):
    slides = set([])

    for root, dirnames, filenames in os.walk(path):
        if root.count(os.sep) <= cutoff:
            for filename in filenames:
                parent_path, parent_name = os.path.split(root)
                if is_slide(filename): slides.add(parent_name)

    return list(slides)
예제 #5
0
def rename_slide(old, new, root=None, relink=True, verbose=False):
	THUMB_NAME = "-thumb.jpg"
	FULL_NAME = "-full.jpg"

	if root is None:
		root = '.' # current directory

	if not os.path.exists(old):
		raise IOError("%s does not exist" % old)

	if not is_slide(old):
		raise TypeError("%s is not a valid slide" % old)

	
	old_slide_name = os.path.basename(old)
	new_slide_name = os.path.basename(new)

	inner_file, slide_type = parse_slide(old)

	#relink first so we don't have to worry about adjusting file paths
	if relink:
		renamer = mv_refs(old_slide_name, new_slide_name)
		parse_folder(root, actions=[renamer], verbose=verbose)


	#rename inner file
	inner_pieces = os.path.splitext(inner_file)
	new_inner_file = os.path.join(old,new_slide_name+inner_pieces[1])
	safe_rename(inner_file, new_inner_file)

	#rename -thumb.jpg if it exists
	old_thumb = os.path.join(old,old_slide_name+THUMB_NAME)
	new_thumb = os.path.join(old,new_slide_name+THUMB_NAME)
	if os.path.exists(old_thumb): safe_rename(old_thumb,new_thumb)

	#rename -full.jpg if it exists
	old_full = os.path.join(old,old_slide_name+FULL_NAME)
	new_full = os.path.join(old,new_slide_name+FULL_NAME)
	if os.path.exists(old_full): safe_rename(old_full,new_full)

	#rename outer parent folder
	safe_rename(old, new)
예제 #6
0
파일: ctls.py 프로젝트: iroc7/VELVEEVA
def parseFolder(src, **kwargs):
    actions = kwargs.get("actions", [])
    CUTOFF = kwargs.get("cutoff", float("inf"))
    root = kwargs["root"]
    out = kwargs["out"]

    username = kwargs["username"]
    password = kwargs["password"]
    email = kwargs.get("email", None)

    version = parseCurrentVersion(root)

    source_path = os.path.join(root, src)
    dest_path = os.path.join(root, out)

    novalidate = kwargs["novalidate"]
    htmlonly = kwargs["htmlonly"]

    if not os.path.exists(dest_path): os.makedirs(dest_path)

    matches = []
    for root, dirnames, filenames in os.walk(source_path):
        for filename in fnmatch.filter(filenames, "*.zip"):
            if novalidate:
                matches.append(os.path.join(root, filename))
            else:
                if is_slide(os.path.join(root, filename)):
                    matches.append(os.path.join(root, filename))

    control_files = [
        createRecordString(m,
                           version=version,
                           username=username,
                           password=password,
                           email=email) for m in matches
    ]

    for control in control_files:
        with open(os.path.join(dest_path, control['filename']), 'w') as f:
            f.write(control['record'])
예제 #7
0
파일: publish.py 프로젝트: iroc7/VELVEEVA
def match_zips_to_ctls(zip_path, ctl_path, novalidate=False):
    def glob_walk(path, ext):
        matches = []
        for root, dirnames, filenames in os.walk(path):
            for filename in fnmatch.filter(filenames, "*" + ext):
                matches.append(os.path.join(root, filename))
        return matches

    def does_file_exist(fname):
        exists = os.path.exists(fname)
        if not exists:
            print("%s does not exist!" % fname)
            sys.stdout.flush()
        return exists

    def all_exists(folders):
        return reduce(lambda acc, arg: acc and does_file_exist(arg), folders,
                      True)

    def base_filename(path):
        return os.path.splitext(os.path.split(path)[-1])[0]

    zips = glob_walk(zip_path, '.zip')
    ctls = glob_walk(ctl_path, '.ctl')

    if novalidate:
        good_zips = [x for x in zips if does_file_exist(x)]
    else:
        good_zips = [x for x in zips if does_file_exist(x) and is_slide(x)]

    good_ctls = [x for x in ctls if does_file_exist(x)]

    both = list(
        set([base_filename(x)
             for x in good_zips]) & set([base_filename(x) for x in good_ctls]))

    return [os.path.join(zip_path, x + ".zip")
            for x in both], [os.path.join(ctl_path, x + ".ctl") for x in both]