Persist class

@[in] file - path to where persist data is stored
@[in] keys - list of strings to scramble together with script load path as an internal guid
@[in] log  - log function (such as logule.get('debug') || console.log) for printing
353281
function Persist(cacheFile, keys, log) {
  var pdata = (cacheFile) ? JSON.parse(fs.readFileSync(cacheFile, 'utf8')) : {}
    , guid = makeGuid(keys);

  pdata[guid] = pdata[guid] || {};

  // this is the only member that needs access to the full object and the file
  this.save = function () {
    if (cacheFile) {
      fs.writeFileSync(cacheFile, JSON.stringify(pdata));
    }
  };

  // members need only know their config object
  this.cfg = pdata[guid];
  this.cfg.opts = this.cfg.opts || {};

  // was a logger passed down?
  this.log = (type.isFunction(log)) ? log : noop;
}
639455
function parseStringPropertyPath(propertyPath) {
            //jshint maxcomplexity:13
            //jshint maxdepth:3
            //REASON: taken from https://github.com/marklagendijk/lodash-deep/blob/master/lodash-deep.js
            //        Need to look at refactoring it.
            var character = '';
            var parsedPropertyPath = [];
            var parsedPropertyPathPart = '';
            var escapeNextCharacter = false;
            var isSpecialCharacter = false;
            var insideBrackets = false;

            // Walk through the path and find backslashes that escape periods or other backslashes, and split on unescaped
            // periods and brackets.
            for (var i = 0; i < propertyPath.length; i++) {
                character = propertyPath[i];
                isSpecialCharacter = (character === '\\' || character === '[' || character === ']' || character === '.');

                if (isSpecialCharacter && !escapeNextCharacter) {
                    if (insideBrackets && character !== ']') {
                        throw new SyntaxError('unexpected "' + character + '" within brackets at character ' + i + ' in property path ' + propertyPath);
                    }

                    switch (character) {
                        case '\\':
                            escapeNextCharacter = true;
                            break;
                        case ']':
                            insideBrackets = false;
                            break;
                        case '[':
                            insideBrackets = true;
                            /* falls through */
                        case '.':
                            parsedPropertyPath.push(parsedPropertyPathPart);
                            parsedPropertyPathPart = '';
                            break;
                    }
                } else {
                    parsedPropertyPathPart += character;
                    escapeNextCharacter = false;
                }
            }

            if (parsedPropertyPath[0] === '') {
                //allow '[0]', or '.0'
                parsedPropertyPath.splice(0, 1);
            }

            // capture the final part
            parsedPropertyPath.push(parsedPropertyPathPart);
            return parsedPropertyPath;
        }
1155730
function logentriesConnect(options={}) {
    // Define path to access specific account, log set and log.
    let pathname = '/'       + encodeURIComponent(options.account) +
                   '/hosts/' + encodeURIComponent(options.logset) +
                   '/'       + encodeURIComponent(options.log) + '/';

    // Bind path argument in query functions.
    let json = logentriesJsonStream.bind(null, pathname);
    let raw  = logentriesRawStream.bind(null, pathname);

    return Object.assign(json, {
        json : json,
        raw  : raw
    });
}
521215
function saveRoot(msg, callback) {
            var persisted,
                numberOfPersistedObjects,
                wrappedCallback,
                callbacks;

            logger.debug('saveRoot msg', msg);

            if (!state.viewer && !state.readOnlyProject && state.nodes[ROOT_PATH]) {
                if (state.msg && msg) {
                    state.msg += '\n' + msg;
                } else {
                    state.msg = msg;
                }

                if (state.transactions.opened === 0) {
                    ASSERT(state.project && state.core && state.branchName);

                    callbacks = state.transactions.callbacks;
                    state.transactions.callbacks = [];

                    wrappedCallback = function (err, result) {
                        if (err) {
                            logger.error('saveRoot failure', err);
                        } else {
                            logger.debug('saveRoot', result);
                        }

                        callbacks.forEach(function (cb) {
                            cb(err, result);
                        });
                    };

                    logger.debug('is NOT in transaction - will persist.');
                    // console.time('persist');
                    persisted = state.core.persist(state.nodes[ROOT_PATH].node);
                    // console.timeEnd('persist');
                    logger.debug('persisted', persisted);
                    numberOfPersistedObjects = Object.keys(persisted.objects).length;
                    if (numberOfPersistedObjects === 0) {
                        logger.warn('No changes after persist will return from saveRoot.');
                        wrappedCallback(null);
                        return;
                    } else if (numberOfPersistedObjects > 200) {
                        //This is just for debugging
                        logger.warn('Lots of persisted objects', numberOfPersistedObjects);
                    }

                    // Make the commit on the storage (will emit hashUpdated)
                    storage.makeCommit(
                        state.project.projectId,
                        state.branchName,
                        [state.commitHash],
                        persisted.rootHash,
                        persisted.objects,
                        state.msg,
                        wrappedCallback
                    );

                    state.msg = '';
                } else {
                    logger.debug('is in transaction - will NOT persist.');

                }
            } else {
                //TODO: Why is this set to empty here?
                state.msg = '';
                callback && callback(null);
            }
        }
1212296
function Persistable (key, value) {
        const __self = this;
        __self.key = key;

        // Set value and type of object.
        if (value === undefined || value === null) {
            __self.value = undefined;
            __self.type = typeof undefined;
        } else if (value instanceof Array) {
            __self.value = [];
            value.forEach(function (e, i) {
                __self.value.push(new Persistable(key + '[' + i + ']', e));
            });
            __self.type = Type.ARRAY;
        } else {
            switch (typeof value) {
                case Type.STRING:
                case Type.NUMBER:
                case Type.BOOLEAN:
                    __self.value = value;
                    __self.type = typeof value;
                    break;
                case Type.OBJECT:
                    __self.value = [];
                    Object.keys(value).forEach(function (e) {
                        __self.value.push(new Persistable(key + '[' + e + ']', value[e]));
                    });
                    __self.type = typeof value;
                    break;
                default:
                    _logUnknownType(typeof value);
            }
        }

        __self.timestamp = Date.now();

        __self.toOriginal = function () {
            return _fromPersistable(__self);
        };
    }
1369174
def _try_persist_settings(serializable_data: dict):
    
    with open(CONFIG_FILE, "w") as json_file:
            json.dump(serializable_data, json_file, indent=4)
1094172
function parseIndexedPaths(path) {
                var opensb = path.lastIndexOf('[');
                info.entityPath = path.substring(0, opensb);  // path to entity is before last [
                var propertyPath = path.substring(opensb + 1, path.length - 1); // property is between [ ]
                // eval it, in case it's an angular expression
                try { var evalPath = info.scope.$eval(propertyPath); }
                catch (_) { }
                info.propertyPath = evalPath ? evalPath : propertyPath;
            }
110439
function (logInst) {

	var log_id = logInst.id;

	// create index to buffer map, if not exist
	if (l_logBufferIdxByID.hasOwnProperty(log_id) === false)
		l_logBufferIdxByID[log_id] = [];

	l_logBufferIdxByID[log_id].push(logInst);

	l_logBuffer.enqueue(logInst,

		// callback to write log
		function (tmpLog) {

			// show notice if queued log exceeds limit (once each time multiples of the limit is reached)
			if ((l_logBuffer.getLength() > 0) && (l_logBuffer.getLength() % l_logBufferOverloadLimit === 0)) {
				console.log(l_name + '::l_writeLog::' + SR.Tags.YELLOW + 'log len=' + l_logBuffer.getLength() + SR.Tags.ERREND);
			}

			// lock individual log instance            
			if (l_logs.hasOwnProperty(tmpLog.id) === true) {
				// if we're busy writing now, wait till next time
				if (l_logs[tmpLog.id].writing === true)
					return false;

				// lock the writing for this id
				l_logs[tmpLog.id].writing = true;

				SR.fs.writeSync(tmpLog.fd, tmpLog.msg, undefined, undefined);

				// remove a flag record from topmost
				if (l_logBufferIdxByID.hasOwnProperty(tmpLog.id) === true)
					l_logBufferIdxByID[tmpLog.id].shift();

				l_logs[tmpLog.id].writing = false;
			}

			// NOTE: processing will pause here if id doesn't exist in l_logs
			// TODO: right behavior?
			return true;
		}
	);
}
969129
function () {
            var res = this._persistentStorage;
            if (res == null) {
                if (this.data) {
                    res = this.data[Aria.FRAMEWORK_PREFIX + "persist::" + this.tplClasspath];
                    if (res == null) {
                        res = {};
                        this.data[Aria.FRAMEWORK_PREFIX + "persist::" + this.tplClasspath] = res;
                    }
                } else {
                    res = {};
                }
                this._persistentStorage = res;
            }
            return res;
        }
323450
def debug_contents(self, indent=1, file=sys.stdout, _ids=None):
        """"""
        klasses = list(self.__class__.__mro__)
        klasses.reverse()

        # print special attributes "bottom up"
        previous_attrs = ()
        for c in klasses:
            attrs = getattr(c, '_debug_contents', ())

            # if we have seen this list already, move to the next class
            if attrs is previous_attrs:
                continue

            for attr in attrs:
                file.write("%s%s = %s\n" % ("    " * indent, attr, getattr(self, attr)))
            previous_attrs = attrs

        # build a list of property identifiers "bottom up"
        property_names = []
        properties_seen = set()
        for c in klasses:
            for prop in getattr(c, 'properties', []):
                if prop.identifier not in properties_seen:
                    property_names.append(prop.identifier)
                    properties_seen.add(prop.identifier)

        # print out the values
        for property_name in property_names:
            property_value = self._values.get(property_name, None)

            # printing out property values that are None is tedious
            if property_value is None:
                continue

            if hasattr(property_value, "debug_contents"):
                file.write("%s%s\n" % ("    " * indent, property_name))
                property_value.debug_contents(indent+1, file, _ids)
            else:
                file.write("%s%s = %r\n" % ("    " * indent, property_name, property_value))
1157706
String getJsFilename(String classname, String fwk) {
		String path = classname.replaceAll("\\.", File.separator);
		if (null != fwk) {
			return File.separator + path + "." + fwk + Constants.JS;
		}
		return File.separator + path + Constants.JS;
	}
1129478
function () {
            this._logsPerClasspath = {};
            var i, j, iLog, jLog, max, end;
            max = 0;
            for (i = 0; i < this._nbLogs; i++) {
                iLog = this._logs[i];
                if (iLog.start && !("length" in iLog)) {
                    for (j = i + 1; j < this._nbLogs; j++) {
                        jLog = this._logs[j];
                        if (jLog.stop && jLog.classpath == iLog.classpath) {
                            if (!jLog.id || iLog.id === jLog.id) {
                                this._logs.splice(j, 1);
                                this._nbLogs--;
                                iLog.length = jLog.stop - iLog.start;
                                iLog.start = iLog.start - this._startTime;
                                break;
                            }
                        }
                    }
                    if (!("length" in iLog)) {
                        // no matching call to $stopMeasure
                        iLog.length = 0;
                        iLog.start = iLog.start - this._startTime;
                    }
                } else if (iLog.timestamp) {
                    iLog.start = iLog.timestamp - this._startTime;
                    iLog.length = 0;
                    delete iLog.timestamp;
                }

                if (!("msg" in iLog)) {
                    iLog.msg = 'NO MESSAGE';
                }

                end = iLog.start + iLog.length;
                if (end > max) {
                    max = end;
                }

                // add in processed logs object
                if (!this._logsPerClasspath[iLog.classpath]) {
                    this._logsPerClasspath[iLog.classpath] = {};
                }
                var cpLog = this._logsPerClasspath[iLog.classpath];
                if (!cpLog[iLog.msg]) {
                    cpLog[iLog.msg] = [0];
                }
                cpLog[iLog.msg].push(iLog);
                cpLog[iLog.msg][0] += iLog.length;
            }
            this._logsPerClasspath._max = max;
        }
955348
@Override
    public void persistJoinTable(JoinTableData joinTableData)
    {
        String joinTableName = joinTableData.getJoinTableName();
        String joinColumnName = joinTableData.getJoinColumnName();
        String invJoinColumnName = joinTableData.getInverseJoinColumnName();
        Map<Key, List<TableOperation>> operations = new HashMap<Key, List<TableOperation>>();

        Table schemaTable = tableAPI.getTable(joinTableName);
        Row row = schemaTable.createRow();

        // String primaryKey = joinColumnName + SEPERATOR + invJoinColumnName;

        KunderaCoreUtils.printQuery("Persist Join Table:" + joinTableName, showQuery);
        Map<Object, Set<Object>> joinTableRecords = joinTableData.getJoinTableRecords();

        try
        {
            for (Object pk : joinTableRecords.keySet())
            {
                // here pk is join column name and it's values would become
                // inverse join columns

                NoSqlDBUtils.add(schemaTable.getField(joinColumnName), row, pk, joinColumnName);
                Set<Object> values = joinTableRecords.get(pk);
                for (Object childId : values)
                {
                    // what if join or inverse join column is null? Not handling
                    // as ideally it should be handled in core itself!

                    NoSqlDBUtils.add(schemaTable.getField(invJoinColumnName), row, childId, invJoinColumnName);

                    NoSqlDBUtils.add(schemaTable.getField(JOIN_TABLE_PRIMARY_KEY_NAME), row,
                            pk.toString() + SEPERATOR + childId.toString(), JOIN_TABLE_PRIMARY_KEY_NAME);

                    addOps(operations, schemaTable, row);
                }
            }

            execute(operations);
        }
        finally
        {
            operations.clear();
            operations = null;
        }
    }
934246
def _persist_inplace(self, **kwargs):
        
        # access .data to coerce everything to numpy or dask arrays
        lazy_data = {k: v._data for k, v in self.variables.items()
                     if isinstance(v._data, dask_array_type)}
        if lazy_data:
            import dask

            # evaluate all the dask arrays simultaneously
            evaluated_data = dask.persist(*lazy_data.values(), **kwargs)

            for k, data in zip(lazy_data, evaluated_data):
                self.variables[k].data = data

        return self
1183183
function getFilePathFromLine(bundleFile, line, variables) {
	// handle variables
	var varRegex = /@{([^}]+)}/;
	var match;
	while (match = line.match(varRegex)) {
		var varName = match[1];
		if (!variables || typeof (variables[varName]) === 'undefined')
			throw new gutil.PluginError(pluginName, bundleFile.path + ': variable "' + varName + '" is not specified');

		var varValue = variables[varName];
		line = line.substr(0, match.index) + varValue + line.substr(match.index + match[0].length);
	}

	if (line === '')
		return null;
	
	// handle `!` negated file paths
	var negative = line[0] === '!';
	if (negative)
		line = line.substr(1);

	// get file path for line
	var filePath;
	if (line.indexOf('./') === 0)
		filePath = path.resolve(bundleFile.cwd, line);
	else
		filePath = path.resolve(bundleFile.base, line);
	
	// return path
	if (negative)
		return '!' + filePath;
	return filePath;
}
1162411
private String persistWorkUnit(final Path workUnitFileDir, final WorkUnit workUnit, ParallelRunner stateSerDeRunner)
      throws IOException {
    final StateStore stateStore;
    String workUnitFileName = workUnit.getId();

    if (workUnit instanceof MultiWorkUnit) {
      workUnitFileName += MULTI_WORK_UNIT_FILE_EXTENSION;
      stateStore = stateStores.getMwuStateStore();
    } else {
      workUnitFileName += WORK_UNIT_FILE_EXTENSION;
      stateStore = stateStores.getWuStateStore();
    }

    Path workUnitFile = new Path(workUnitFileDir, workUnitFileName);
    final String fileName = workUnitFile.getName();
    final String storeName = workUnitFile.getParent().getName();
    stateSerDeRunner.submitCallable(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        stateStore.put(storeName, fileName, workUnit);
        return null;
      }
    }, "Serialize state to store " + storeName + " file " + fileName);

    return workUnitFile.toString();
  }
1140833
function embed(sourcePath, relativePaths, name, done) {
  var items = '';
  each(relativePaths, function(relativePath, next) {
    var fullPath = path.join(sourcePath, relativePath);
    fs.readFile(fullPath, 'utf8', function(err, text) {
      if (err) return next(err);
      items += '  $templateCache.put(\'' +
        inline(relativePath) + '\', \'' +
        inline(text.trim()) + '\');\n';
      next();
    });
  }, function(err) {
    if (err) return done(err);
    console.log(
      'angular.module(\'' + inline(name) + '\', []).run([\'$templateCache\', function($templateCache) {\n' +
      items +
      '}]);');
    done();
  });
}