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)
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)
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)
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
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)
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)
def currentWorkstationRef(): currentId = getFromConfig(configWorkstationId) return workstationRef(currentId)
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)