Exemplo n.º 1
0
def createMetaBlob(state, customTitle=None, customId=None):
    workstationId = customId if customId else getFromConfig(configWorkstationId)
    workstationTitle = customTitle if customTitle else getFromConfig(configWorkstationTitle)
    now = datetime.datetime.now()
    meta = {
        metaWorkstationIdKey: workstationId,
        metaWorkstationTitleKey: workstationTitle,
        metaTimeKey: now.strftime(dateFormat),
        metaStateKey: state
    }
    metaJson = json.dumps(meta)
    return popenCommunicate("git hash-object -w --stdin", metaJson)
Exemplo n.º 2
0
def init(flags=[]):
    workstationId = getFromConfig(configWorkstationId)
    if not workstationId:
        workstationId = str(uuid.uuid1())
        setToConfig(configWorkstationId, workstationId, isGlobal=True)
    print(messages.workstationIdSettedFormat.format(workstationId))

    workstationTitle = getFromConfig(configWorkstationTitle)
    if not workstationTitle:
        workstationTitle = input(messages.workstationTitleInputMessage)
        setToConfig(configWorkstationTitle, workstationTitle, isGlobal=True)
    print(
        messages.workstationTitleSettedFormat.format(workstationTitle,
                                                     configWorkstationTitle))

    remote = getFromConfig(configRemote)
    if not remote:
        remote = input(messages.remoteInputMessage)
        if not remote:
            remote = "origin"
        setToConfig(configRemote, remote)
    print(messages.remoteSettedFormat.format(remote, configRemote))

    registerWorkstation(workstationId)
Exemplo n.º 3
0
def saveCurrentState(state=None, quiet=False, customTitle=None, customId=None):
    workstation = customId if customId else getFromConfig(configWorkstationId)
    currentState = state if state else createStateTree()
    registerWorkstation(workstation)
    
    ref = workstationRef(workstation)
    if ref:
        items = treeItems(ref)
    else:
        items = list()
    
    meta = createMetaBlob(currentState, customTitle=customTitle, customId=customId)
    items = updateMetaInItems(items, meta)
    items = updateStateInItems(items, currentState)
    workstationTree = createTree(items)
    updateRef(ref, workstationTree, quiet=quiet)
Exemplo n.º 4
0
def availableMetas(withFetch=False, noCurrent=False):
    if withFetch:
        fetchAllRefs()
        
    refs = workstationsRefs()
    currentId = getFromConfig(configWorkstationId)
    metaDicts = list()
   
    for ref in refs:
        if noCurrent and currentId in ref:
            continue
        items = treeItems(ref)
        stationMetaItems = filter(lambda item: metaBlobName in item, items)
        stationMetaShas = map(itemSha, stationMetaItems)
        stationMetaDicts = map(metaDict, stationMetaShas)
        metaDicts.extend(stationMetaDicts)

    return metaDicts
Exemplo n.º 5
0
def startAutosave(flags=[]):
    forcedComponent = " " + Flags.forced.value[
        0] if Flags.forced in flags else ""
    period = getFromConfig(configSavePeriod)
    if not period:
        print(
            messages.savePeriodUndefinedFormat.format(
                configSavePeriod,
                Subcommands.autosave.value + " " + Flags.start.value[0]))
        return

    stopAutosave([Flags.quiet])

    scriptDir = Path(os.path.dirname(__file__))
    autosaveScript = scriptDir / "utils" / autosaveScriptFile
    logfilePath = scriptDir / autosaveLogFile
    logfile = open(str(logfilePath), 'w')
    autosaveCmd = "python '" + str(autosaveScript) + "' " + str(
        period) + forcedComponent + " " + autosaveDirSeparator + mainDir()
    backgroundDetachedPopen(autosaveCmd, logfile=logfile)
Exemplo n.º 6
0
def fetchRef(ref, hideErrors=False):
    remote = getFromConfig(configRemote)
    errors = DEVNULL if hideErrors else None
    cmd = "git fetch --quiet -f " + remote + " " + ref + ":" + ref
    print(cmd)
    call(cmd, errors=errors, out=errors)
Exemplo n.º 7
0
def currentWorkstationRef():
    currentId = getFromConfig(configWorkstationId)
    return workstationRef(currentId)
Exemplo n.º 8
0
def updateRef(ref, sha, quiet=False, renewRemote=True):
    quietComponent = " --quiet" if quiet else ""
    call("git update-ref " + ref + " " + sha)
    if renewRemote:
        call("git push --force " + getFromConfig(configRemote) + " " + ref + quietComponent)