コード例 #1
0
ファイル: cl_utils.py プロジェクト: thespacedoctor/projector
def setup_projects_from_file_input(log, settings):
    """
    *cl utils*

    **Key Arguments:**
        - ``dbConn`` -- mysql database connection
        - ``log`` -- logger

    **Return:**
        - None

    .. todo::

        - @review: when complete, clean cl_utils function
        - @review: when complete add logging
        - @review: when complete, decide whether to abstract function to another module
    """
    log.info("starting the ``cl_utils`` function")

    basePath = settings["projector"]["queue directory"]
    for d in os.listdir(basePath):
        filePath = os.path.join(basePath, d)
        if os.path.isfile(filePath):
            readFile = codecs.open(filePath, encoding="utf-8", mode="r")
            data = readFile.readlines()
            readFile.close()

        if data[0].strip() not in ["work", "home"]:
            print "Wrong data format for file %(filePath)s" % locals()
        else:
            projectName = data[1].strip()
            if data[0].strip() == "home":
                userId = "*****@*****.**"
                stack = "home projects"
                dropboxPath = "/notes/thespacedoctor-wiki/projects/"
            else:
                userId = "*****@*****.**"
                stack = "work projects"
                dropboxPath = "/notes/astronotes-wiki/projects/"

            gmail_utils(log=log, settings=settings, userId=userId).create_label("projects/" + projectName)
            evernote_utils(log=log, settings=settings).create_notebook(nbName=projectName, stack=stack)

            mkdir(log=log, settings=settings, dropboxPath=dropboxPath + projectName).get()

            os.remove(filePath)

    log.info("completed the ``cl_utils`` function")
    return None
コード例 #2
0
ファイル: cl_utils.py プロジェクト: thespacedoctor/projector
def main(arguments=None):
    """
    *The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command*
    """
    # setup the command-line util settings
    su = tools(arguments=arguments, docString=__doc__, logLevel="DEBUG", options_first=False, projectName="projector")
    arguments, settings, log, dbConn = su.setup()

    # tab completion for raw_input
    readline.set_completer_delims(" \t\n;")
    readline.parse_and_bind("tab: complete")
    readline.set_completer(tab_complete)

    # unpack remaining cl arguments using `exec` to setup the variable names
    # automatically
    for arg, val in arguments.iteritems():
        if arg[0] == "-":
            varname = arg.replace("-", "") + "Flag"
        else:
            varname = arg.replace("<", "").replace(">", "")
        if isinstance(val, str) or isinstance(val, unicode):
            exec (varname + " = '%s'" % (val,))
        else:
            exec (varname + " = %s" % (val,))
        if arg == "--dbConn":
            dbConn = val
        log.debug("%s = %s" % (varname, val))

    ## START LOGGING ##
    startTime = times.get_now_sql_datetime()
    log.info("--- STARTING TO RUN THE cl_utils.py AT %s" % (startTime,))

    # set options interactively if user requests
    if "interactiveFlag" in locals() and interactiveFlag:

        # load previous settings
        moduleDirectory = os.path.dirname(__file__) + "/resources"
        pathToPickleFile = "%(moduleDirectory)s/previousSettings.p" % locals()
        try:
            with open(pathToPickleFile):
                pass
            previousSettingsExist = True
        except:
            previousSettingsExist = False
        previousSettings = {}
        if previousSettingsExist:
            previousSettings = pickle.load(open(pathToPickleFile, "rb"))

        # x-raw-input
        # x-boolean-raw-input
        # x-raw-input-with-default-value-from-previous-settings

        # save the most recently used requests
        pickleMeObjects = []
        pickleMe = {}
        theseLocals = locals()
        for k in pickleMeObjects:
            pickleMe[k] = theseLocals[k]
        pickle.dump(pickleMe, open(pathToPickleFile, "wb"))

    if home:
        userId = "*****@*****.**"
        stack = "home projects"
        dropboxPath = "/notes/thespacedoctor-wiki/projects/"
    elif work:
        userId = "*****@*****.**"
        stack = "work projects"
        dropboxPath = "/notes/astronotes-wiki/projects/"

    # CALL FUNCTIONS/OBJECTS
    if create:
        gmail_utils(log=log, settings=settings, userId=userId).create_label("projects/" + projectName)
        evernote_utils(log=log, settings=settings).create_notebook(nbName=projectName, stack=stack)
        mkdir(log=log, settings=settings, dropboxPath=dropboxPath + projectName).get()
        this = touch_file(log=log, settings=settings, destination=dropboxPath + projectName + ".remove").touch()

        # try:
        #     devonthink_indexer(
        #         log=log,
        #         settings=settings,
        #     ).get()

        #     time.sleep(3)
        #     devonthink_indexer(
        #         log=log,
        #         settings=settings,
        #     ).get()
        # except:
        #     pass

    if remote:
        setup_projects_from_file_input(log=log, settings=settings)

    if auth:
        evernote_utils(log=log, settings=settings).authenticate()

    # if dt:
    #     devonthink_indexer(
    #         log=log,
    #         settings=settings,
    #     ).get()

    if ls:
        gmail_utils(log=log, settings=settings, userId=userId).list_live_projects(archive=archiveFlag)

    if "dbConn" in locals() and dbConn:
        dbConn.commit()
        dbConn.close()
    ## FINISH LOGGING ##
    endTime = times.get_now_sql_datetime()
    runningTime = times.calculate_time_difference(startTime, endTime)
    log.info("-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --" % (endTime, runningTime))

    return