예제 #1
0
파일: act.py 프로젝트: PGDJ/Workflows
def act():
    args = alp.args()
    if args[0] == "configure":
        url = args[1]
        sig = args[2]

        s = alp.Settings()
        s_dict = {"url": url}
        s.set(**s_dict)

        kc = alp.Keychain("yourls_stats")
        if not kc.retrievePassword("signature"):
            kc.storePassword("signature", sig)
        else:
            kc.modifyPassword("signature", sig)

        info = alp.readPlist(alp.local("info.plist"))
        objs = info['objects']
        kw = None
        for o in objs:
            if o['type'] == "alfred.workflow.input.scriptfilter":
                kw = o['config']['keyword']
                break

        if kw:
            scpt = "tell application \"Alfred 2\" to search \"{0}\"".format(kw)
            call(["osascript", "-e", scpt])

        print "Yourls Configured"

    elif args[0] == "copy":
        print args[1]
예제 #2
0
def act():
    args = alp.args()
    if args[0] == "configure":
        url = args[1]
        sig = args[2]

        s = alp.Settings()
        s_dict = {"url": url}
        s.set(**s_dict)

        kc = alp.Keychain("yourls_stats")
        if not kc.retrievePassword("signature"):
            kc.storePassword("signature", sig)
        else:
            kc.modifyPassword("signature", sig)

        info = alp.readPlist(alp.local("info.plist"))
        objs = info['objects']
        kw = None
        for o in objs:
            if o['type'] == "alfred.workflow.input.scriptfilter":
                kw = o['config']['keyword']
                break

        if kw:
            scpt = "tell application \"Alfred 2\" to search \"{0}\"".format(kw)
            call(["osascript", "-e", scpt])

        print "Yourls Configured"

    elif args[0] == "copy":
        print args[1]
예제 #3
0
파일: feedback.py 프로젝트: PGDJ/Workflows
def do_feedback():
    q = alp.args()
    flowPath = os.path.split(alp.local())[0]
    cache = alp.jsonLoad("cache.json", default={})
    day_secs = 24 * 60 * 60
    force = (len(q) > 0 and q[0] == "|force|")
    t = time.time()
    if (force):
        import shutil
        _c = alp.cache()
        _s = alp.storage()
        shutil.rmtree(_c)
        shutil.rmtree(_s)

    if (cache.get("cache_time", 0) + day_secs > t) and not force:
        candidates = cache.get("cached_workflows", [])
    else:
        candidates = []
        for dirpath, dirnames, filenames in os.walk(flowPath, topdown=False, followlinks=True):
            for aFile in filenames:
                if aFile == "update.json":
                    try:
                        fn = os.path.join(dirpath, "Info.plist")
                        if not os.path.exists(fn):
                            fn = os.path.join(dirpath, "info.plist")

                        plist = alp.readPlist(fn)
                    except IOError as e:
                        alp.log("Exception: Info.plist not found ({0}).".format(e))
                        continue
                    else:
                        name = plist["name"]
                        local_description = plist["description"]
                        the_json = os.path.join(dirpath, aFile)
                        the_icon = os.path.join(dirpath, "icon.png")
                        if name != "Alleyoop":
                            candidates.append(dict(name=name, json=the_json,
                                icon=the_icon, path=dirpath,
                                description=local_description))
                        else:
                            downloads_path = os.path.expanduser("~/Downloads/")
                            candidates.append(dict(name=name, json=the_json,
                                icon=the_icon, path=downloads_path,
                                description=local_description))
        new_cache = dict(cache_time=t, cached_workflows=candidates)
        alp.jsonDump(new_cache, "cache.json")

    threads = []
    for candidict in candidates:
        try:
            with codecs.open(candidict["json"]) as f:
                local = json.load(f, encoding="utf-8")
        except Exception as e:
            alp.log("{0} may no longer exist: {1}".format(candidict["name"], e))
            continue

        ot = OopThread(local['remote_json'], force, candidict, local)
        threads.append(ot)
        ot.start()
    manage_threads(threads)
예제 #4
0
def setKeyChainPassword(password):
    keychain = alp.Keychain(alp.bundle())
    settings = alp.readPlist(SETTINGS_PATH)
    username = settings["username"]

    if settings["passwordSet"] == "true":
        keychain.modifyPassword(username, password)
    else:
        keychain.storePassword(username, password)
        settings["passwordSet"] = "true"

    settings["credentialsChanged"] = "true"
    alp.writePlist(settings, SETTINGS_PATH)
예제 #5
0
def main():
    """
    Everything dispatches from this function.
    """
    global settings

    # Create default settings if necessary
    createSettingsFile()

    # Read settings
    settings = alp.readPlist(SETTINGS_PATH)

    # Process the settings
    if settings["firstRun"] == "true":
        udpateDatabaseFromKippt()
        settings["firstRun"] = "false"
        settings["credentialsChanged"] = "false"
        alp.writePlist(settings, SETTINGS_PATH)
    elif settings["credentialsChanged"] == "true":
        udpateDatabaseFromKippt()
        settings["credentialsChanged"] = "false"
        alp.writePlist(settings, SETTINGS_PATH)
    elif settings["updateClips"] == "true":
        udpateDatabaseFromKippt()
        settings["updateClips"] = "false"
        alp.writePlist(settings, SETTINGS_PATH)

    # Get the keywords
    args = alp.args()
    if len(args) < 1:
        return

    # Execute the search
    items = search(args)
    if items is not None:
        alp.feedback(items)
    else:
        print "No items found"
예제 #6
0
def main():
    """
    Everything dispatches from this function.
    """
    global settings

    # Create default settings if necessary
    createSettingsFile()

    # Read settings
    settings = alp.readPlist(SETTINGS_PATH)

    # Process the settings
    if settings["firstRun"] == "true":
        udpateDatabaseFromKippt()
        settings["firstRun"] = "false"
        settings["credentialsChanged"] = "false"
        alp.writePlist(settings, SETTINGS_PATH)
    elif settings["credentialsChanged"] == "true":
        udpateDatabaseFromKippt()
        settings["credentialsChanged"] = "false"
        alp.writePlist(settings, SETTINGS_PATH)
    elif settings["updateClips"] == "true":
        udpateDatabaseFromKippt()
        settings["updateClips"] = "false"
        alp.writePlist(settings, SETTINGS_PATH)

    # Get the keywords
    args = alp.args()
    if len(args) < 1:
        return

    # Execute the search
    items = search(args)
    if items is not None:
        alp.feedback(items)
    else:
        print "No items found"
예제 #7
0
def do_feedback():
    q = alp.args()
    flowPath = os.path.split(alp.local())[0]
    cache = alp.jsonLoad("cache.json", default={})
    day_secs = 24 * 60 * 60
    force = (len(q) > 0 and q[0] == "|force|")
    t = time.time()
    if (force):
        import shutil
        _c = alp.cache()
        _s = alp.storage()
        shutil.rmtree(_c)
        shutil.rmtree(_s)

    if (cache.get("cache_time", 0) + day_secs > t) and not force:
        candidates = cache.get("cached_workflows", [])
    else:
        candidates = []
        for dirpath, dirnames, filenames in os.walk(flowPath,
                                                    topdown=False,
                                                    followlinks=True):
            for aFile in filenames:
                if aFile == "update.json":
                    try:
                        fn = os.path.join(dirpath, "Info.plist")
                        if not os.path.exists(fn):
                            fn = os.path.join(dirpath, "info.plist")

                        plist = alp.readPlist(fn)
                    except IOError as e:
                        alp.log(
                            "Exception: Info.plist not found ({0}).".format(e))
                        continue
                    else:
                        name = plist["name"]
                        local_description = plist["description"]
                        the_json = os.path.join(dirpath, aFile)
                        the_icon = os.path.join(dirpath, "icon.png")
                        if name != "Alleyoop":
                            candidates.append(
                                dict(name=name,
                                     json=the_json,
                                     icon=the_icon,
                                     path=dirpath,
                                     description=local_description))
                        else:
                            downloads_path = os.path.expanduser("~/Downloads/")
                            candidates.append(
                                dict(name=name,
                                     json=the_json,
                                     icon=the_icon,
                                     path=downloads_path,
                                     description=local_description))
        new_cache = dict(cache_time=t, cached_workflows=candidates)
        alp.jsonDump(new_cache, "cache.json")

    threads = []
    for candidict in candidates:
        try:
            with codecs.open(candidict["json"]) as f:
                local = json.load(f, encoding="utf-8")
        except Exception as e:
            alp.log("{0} may no longer exist: {1}".format(
                candidict["name"], e))
            continue

        ot = OopThread(local['remote_json'], force, candidict, local)
        threads.append(ot)
        ot.start()
    manage_threads(threads)
예제 #8
0
listdir = os.getcwd() + "/../" # there has to be a more elegant way to do this... 
# list of directories in the 

dirs = os.walk(listdir).next()[1]
# walk through the directory list array

workflows = {} # empty dictionary to hold the individual workflow information

for item in dirs:
	if item != "alfred-help": # this is just for my debugging purposes and will disappear soon
			plist = listdir + "/" + item + "/info.plist" # find the plist file
 
 			folder = item # the strange foldernames that Alfred assigns the workflows...
			 
			info = alp.readPlist(plist) # alp function
			
			# start to write the markup for the files 
			
			buffer = "<img src=\"file://localhost/" + listdir + item + "/icon.png\" height=\"50px\">      <font size=\"5em\"><b>" + info['name'] + "</b></font>\n<hr>"
			buffer += "\n\n_(" + info['bundleid'] + ") by " + info['createdby'] + "_\n"
			if "disabled" in info:
				if info['disabled']:
					buffer +=  " (<font color=\"red\">disabled</font>)\n" # Indicate that a workflow is disabled

			if info['description']: # Is the description present? Some people don't include these...
				buffer +=  "######<font color=\"gray\">" + info['description'] + "</font>\n"
			else:
				buffer +=  "\n"
			
			# Start to go through the objects to look for keywords, script filters, and hotkeys
예제 #9
0
def setUpdateDatabase():
    settings = alp.readPlist(SETTINGS_PATH)
    settings["updateClips"] = "true"
    alp.writePlist(settings, SETTINGS_PATH)
예제 #10
0
def setUserName(username):
    settings = alp.readPlist(SETTINGS_PATH)
    settings["username"] = username
    settings["credentialsChanged"] = "true"
    alp.writePlist(settings, SETTINGS_PATH)
예제 #11
0
def getKeyChainPassword():
    keychain = alp.Keychain(alp.bundle())
    settings = alp.readPlist(SETTINGS_PATH)
    return keychain.retrievePassword(settings["username"])
예제 #12
0
listdir = os.getcwd(
) + "/../"  # there has to be a more elegant way to do this...
# list of directories in the

dirs = os.walk(listdir).next()[1]
# walk through the directory list array

workflows = {}  # empty dictionary to hold the individual workflow information

for item in dirs:
    if item != "alfred-help":  # this is just for my debugging purposes and will disappear soon
        plist = listdir + "/" + item + "/info.plist"  # find the plist file

        folder = item  # the strange foldernames that Alfred assigns the workflows...

        info = alp.readPlist(plist)  # alp function

        # start to write the markup for the files

        buffer = "<img src=\"file://localhost/" + listdir + item + "/icon.png\" height=\"50px\">      <font size=\"5em\"><b>" + info[
            'name'] + "</b></font>\n<hr>"
        buffer += "\n\n_(" + info['bundleid'] + ") by " + info[
            'createdby'] + "_\n"
        if "disabled" in info:
            if info['disabled']:
                buffer += " (<font color=\"red\">disabled</font>)\n"  # Indicate that a workflow is disabled

        if info['description']:  # Is the description present? Some people don't include these...
            buffer += "######<font color=\"gray\">" + info[
                'description'] + "</font>\n"
        else: