Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 84076a65fb48808d97776f88f95968f496632b56 authored by Alexey Sergushichev on 21 October 2020, 13:33:52 UTC, committed by Alexey Sergushichev on 21 October 2020, 13:33:52 UTC
Example fix
1 parent e7501bc
  • Files
  • Changes
  • 87ad9bb
  • /
  • R
  • /
  • loadSession.R
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:84076a65fb48808d97776f88f95968f496632b56
directory badge Iframe embedding
swh:1:dir:6dd4b3f64d06ebfde201beadc02277047cc9ff0a
content badge Iframe embedding
swh:1:cnt:c6b64d024b691c9deab14a22f5fa80baa4dd5ae9
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
loadSession.R
sessionExists <- function(sessionName) {
    ocpuRoot <- strsplit(getwd(), 'ocpu-temp')[[1]][1]
    sessionPath <- file.path(ocpuRoot, 'ocpu-store', sessionName)

    savedPath <- file.path(sessionPath, 'sess.bin')
    RDataPath <- file.path(sessionPath, '.RData')

    if (file.exists(savedPath)) {
        return (jsonlite::toJSON(list(result=TRUE), auto_unbox = TRUE))
    }

    #-----------------LEGACY----------------------------------- DELETE AFTER 3 JUNE 2019

    if (file.exists(RDataPath)) {
        env <- new.env()
        load(RDataPath, envir = env)
        validForLoading = !is.null(env$es) && !is.null(attr(env$es, 'published'))

        return (jsonlite::toJSON(list(result=validForLoading), auto_unbox = TRUE))
    }

    return (jsonlite::toJSON(list(result=FALSE), auto_unbox = TRUE))
}

publishSession <- function (sessionName, datasetName = sessionName, heatmapJson = NULL) {
    ocpuRoot <- strsplit(getwd(), 'ocpu-temp')[[1]][1]
    sessionPath <- file.path(ocpuRoot, 'ocpu-store', sessionName)

    RDataPath <- paste(sessionPath, '.RData', sep=.Platform$file.sep)
    if (file.exists(RDataPath)) {
        env <- new.env()
        load(RDataPath, envir = env)

        if (!is.null(env$es)) { # this session is for actual dataset
            result <- list()
            datasetName <- ifelse(nchar(datasetName) > 0, datasetName, sessionName)
            result[[datasetName]] <- writeToList(env$es)
            binaryFile <- file.path(getwd(), 'sess.bin')

            writeBin(protolite::serialize_pb(result), binaryFile)
            assign("es", env$es, envir = parent.frame())
            if (!is.null(heatmapJson)) {
                heatmapPath <- file.path(getwd(), 'heatmap.json')
                write(jsonlite::toJSON(heatmapJson, auto_unbox = TRUE, null = 'null'), heatmapPath)
            }

            return (jsonlite::toJSON(basename(binaryFile)))
        }
    }

    stop('Invalid session')
}

loadSession <- function (sessionName) {
    ocpuRoot <- strsplit(getwd(), 'ocpu-temp')[[1]][1]
    sessionPath <- file.path(ocpuRoot, 'ocpu-store', sessionName)

    savedPath <- paste(sessionPath, 'sess.bin', sep=.Platform$file.sep)
    if (file.exists(savedPath)) {
        return (jsonlite::toJSON(basename(savedPath)))
    }

    #---------------------LEGACY------------------------------------- DELETE AFTER 3 JUNE 2019

    RDataPath <- paste(sessionPath, '.RData', sep=.Platform$file.sep)
    if (file.exists(RDataPath)) {
        savedEnv <- load(RDataPath)

        if (!("es" %in% savedEnv) || is.null(attr(es, 'published'))) {
            stop('Invalid session key')
        }

        result <- list()
        result[[sessionName]] <- writeToList(es)
        writeBin(protolite::serialize_pb(result), savedPath)
        return (jsonlite::toJSON(basename(savedPath)))
    }

    stop('Invalid session key')
}

heatmapSettings <- function (sessionName, isTempSession = TRUE) {

    if (isTempSession){
        ocpuRoot <- strsplit(getwd(), 'ocpu-temp')[[1]][1]
        sessionPath <- file.path(ocpuRoot, 'ocpu-store', sessionName)
        heatmapPath <- file.path(sessionPath, 'heatmap.json')
    }
    else{
        preloadedDir <- getOption("phantasusPreloadedDir")
        heatmapPath <- file.path(preloadedDir, paste0(sessionName,'.json'))
    }
    if (file.exists(heatmapPath)) {
        heatmap <- fromJSON(heatmapPath)
        return (jsonlite::toJSON(list(result=heatmap), auto_unbox = TRUE, null = 'null'))
    }

    return (jsonlite::toJSON(list(result=FALSE), auto_unbox = TRUE))
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top