Browse Source

kernel state

master
boB Rudis 6 years ago
parent
commit
204cac3624
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 6
      NAMESPACE
  2. 22
      R/kernel-state.R
  3. 2
      R/mactheknife-package.R
  4. 2
      R/su-hist-file.R
  5. 19
      R/sw-vers.R
  6. 32
      R/system-profile.R
  7. 15
      README.Rmd
  8. 34
      README.md
  9. 11
      man/kernel_state.Rd
  10. 14
      man/sw_vers.Rd
  11. 23
      man/system_profile.Rd

6
NAMESPACE

@ -1,9 +1,15 @@
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
export(kernel_state)
export(read_dsstore) export(read_dsstore)
export(software_update_history) export(software_update_history)
export(sw_vers)
export(system_profile)
import(reticulate) import(reticulate)
import(sys) import(sys)
import(xml2) import(xml2)
importFrom(anytime,anytime) importFrom(anytime,anytime)
importFrom(purrr,"%>%")
importFrom(purrr,flatten_chr)
importFrom(purrr,map_df) importFrom(purrr,map_df)
importFrom(purrr,set_names)

22
R/kernel-state.R

@ -0,0 +1,22 @@
#' Retrieve kernel state information
#'
#' @export
kernel_state <- function() {
res <- sys::exec_internal("sysctl", "-a")
if (res$status != 0) {
stop("Error retrieving kernel state info. Are you on macOS?", call.=FALSE)
}
out <- rawToChar(res$stdout)
purrr::map_df(strsplit(out, "\n")[[1]], ~{
.x <- strsplit(.x, ": ", fixed = TRUE)[[1]]
list(
setting = .x[1],
value = .x[2]
)
})
}

2
R/mactheknife-package.R

@ -7,6 +7,6 @@
#' @docType package #' @docType package
#' @author Bob Rudis (bob@@rud.is) #' @author Bob Rudis (bob@@rud.is)
#' @import reticulate sys xml2 #' @import reticulate sys xml2
#' @importFrom purrr map_df #' @importFrom purrr map_df %>% flatten_chr set_names
#' @importFrom anytime anytime #' @importFrom anytime anytime
NULL NULL

2
R/su-hist-file.R

@ -45,7 +45,7 @@ software_update_history <- function(su_hist_file = "/Library/Receipts/InstallHis
"real" = as.numeric(unlist(grandkids[[i+1]])), "real" = as.numeric(unlist(grandkids[[i+1]])),
"true" = TRUE, "true" = TRUE,
"false" = FALSE, "false" = FALSE,
"array" = list(setNames(list(unlist(grandkids[[i+1]], use.names=FALSE)), key_name)), "array" = list(purrr::set_names(list(unlist(grandkids[[i+1]], use.names=FALSE)), key_name)),
"data" = "TODO", "data" = "TODO",
"UNKNOWN - TODO" "UNKNOWN - TODO"
) )

19
R/sw-vers.R

@ -0,0 +1,19 @@
#' Retrieve macOS Operating System Version Information
#'
#' @return data frame (tibble)
#' @export
sw_vers <- function() {
res <- sys::exec_internal("sw_vers")
if (length(res$stdout) == 0) {
stop('Error retrieving macOS version info. Are you running on macOS?', call.=FALSE)
}
out <- rawToChar(res$stdout)
purrr::map_dfc(strsplit(out, "\n")[[1]], ~{
.x <- strsplit(.x, "\t")[[1]]
as.list(purrr::set_names(.x[2], gsub(":", "", .x[1])))
})
}

32
R/system-profile.R

@ -0,0 +1,32 @@
#' Report system hardware and software configuration
#'
#' TODO Do more than just return an xml document once a generica plist reader
#' is created.
#'
#' @md
#' @note Even the `mini` option takes a noticeable amount of time to complete.
#' @param detail_level how much information to return:
#' - `mini` report with no personal information
#' - `basic` basic hardware and network information
#' - `full` all available information
#' @export
system_profile <- function(detail_level = c("mini", "basic", "full")) {
match.arg(
tolower(trimws(detail_level[1])),
c("mini", "basic", "full")
) -> detail_level
sys::exec_internal(
"system_profiler",
c("-xml", "-detailLevel", "mini")
) -> res
if (res$status != 0) {
stop("Error running system profiler. Are you on macOS?", call.=FALSE)
}
xml2::read_xml(res$stdout)
}

15
README.Rmd

@ -16,8 +16,10 @@ A set of tools/methods and data that are geared towards the 'macOS' ecosystem.
## What's Inside The Tin ## What's Inside The Tin
- `kernel_state`: Retrieve kernel state information
- `read_dsstore`: Read a '.DS_Store' from a file/URL - `read_dsstore`: Read a '.DS_Store' from a file/URL
- `software_update_history`: Retrieve Software Update history - `software_update_history`: Retrieve Software Update history
- `sw_vers`: Retrieve macOS Operating System Version Information
The following functions are implemented: The following functions are implemented:
@ -41,6 +43,12 @@ packageVersion("mactheknife")
``` ```
### Kernel state vars
```{r}
kernel_state()
```
### `.DS_Store` example ### `.DS_Store` example
Using built-in data Using built-in data
@ -80,3 +88,10 @@ str(x)
```{r} ```{r}
software_update_history() software_update_history()
``` ```
### macOS Version Info (short)
```{r}
sw_vers()
```

34
README.md

@ -14,8 +14,10 @@ ecosystem.
## What’s Inside The Tin ## What’s Inside The Tin
- `kernel_state`: Retrieve kernel state information
- `read_dsstore`: Read a ‘.DS\_Store’ from a file/URL - `read_dsstore`: Read a ‘.DS\_Store’ from a file/URL
- `software_update_history`: Retrieve Software Update history - `software_update_history`: Retrieve Software Update history
- `sw_vers`: Retrieve macOS Operating System Version Information
The following functions are implemented: The following functions are implemented:
@ -36,6 +38,27 @@ packageVersion("mactheknife")
## [1] '0.1.0' ## [1] '0.1.0'
### Kernel state vars
``` r
kernel_state()
```
## # A tibble: 1,217 x 2
## setting value
## <chr> <chr>
## 1 user.cs_path /usr/bin:/bin:/usr/sbin:/sbin
## 2 user.bc_base_max 99
## 3 user.bc_dim_max 2048
## 4 user.bc_scale_max 99
## 5 user.bc_string_max 1000
## 6 user.coll_weights_max 2
## 7 user.expr_nest_max 32
## 8 user.line_max 2048
## 9 user.re_dup_max 255
## 10 user.posix2_version 200112
## # ... with 1,207 more rows
### `.DS_Store` example ### `.DS_Store` example
Using built-in data Using built-in data
@ -120,3 +143,14 @@ software_update_history()
## 9 Degrees Pro 4.2.1 2017-01-23 16:06:56 <chr [1]> storedownloadd <NA> ## 9 Degrees Pro 4.2.1 2017-01-23 16:06:56 <chr [1]> storedownloadd <NA>
## 10 WordService 2.8.1 2017-01-23 16:06:57 <chr [1]> storedownloadd <NA> ## 10 WordService 2.8.1 2017-01-23 16:06:57 <chr [1]> storedownloadd <NA>
## # ... with 580 more rows ## # ... with 580 more rows
### macOS Version Info (short)
``` r
sw_vers()
```
## # A tibble: 1 x 3
## ProductName ProductVersion BuildVersion
## <chr> <chr> <chr>
## 1 Mac OS X 10.12.6 16G1405

11
man/kernel_state.Rd

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/kernel-state.R
\name{kernel_state}
\alias{kernel_state}
\title{Retrieve kernel state information}
\usage{
kernel_state()
}
\description{
Retrieve kernel state information
}

14
man/sw_vers.Rd

@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sw-vers.R
\name{sw_vers}
\alias{sw_vers}
\title{Retrieve macOS Operating System Version Information}
\usage{
sw_vers()
}
\value{
data frame (tibble)
}
\description{
Retrieve macOS Operating System Version Information
}

23
man/system_profile.Rd

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/system-profile.R
\name{system_profile}
\alias{system_profile}
\title{Report system hardware and software configuration}
\usage{
system_profile(detail_level = c("mini", "basic", "full"))
}
\arguments{
\item{detail_level}{how much information to return:
\itemize{
\item \code{mini} report with no personal information
\item \code{basic} basic hardware and network information
\item \code{full} all available information
}}
}
\description{
TODO Do more than just return an xml document once a generica plist reader
is created.
}
\note{
Even the \code{mini} option takes a noticeable amount of time to complete.
}
Loading…
Cancel
Save