Browse Source

Package Title/Description change + URL reading for read_dsstore()

master
boB Rudis 6 years ago
parent
commit
f4f1c313a3
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 6
      DESCRIPTION
  2. 3
      R/mactheknife-package.R
  3. 35
      R/read-dsstore.R
  4. 3
      R/utils.R
  5. 17
      README.Rmd
  6. 22
      README.md
  7. 3
      man/mactheknife.Rd
  8. 12
      man/read_dsstore.Rd

6
DESCRIPTION

@ -1,6 +1,6 @@
Package: mactheknife Package: mactheknife
Type: Package Type: Package
Title: Read 'macOS' .DS_Store' Files Title: Various 'macOS'-oriented Tools and Utilities
Version: 0.1.0 Version: 0.1.0
Date: 2018-04-29 Date: 2018-04-29
Authors@R: c( Authors@R: c(
@ -10,8 +10,8 @@ Authors@R: c(
comment = "Python dsstore module <https://github.com/gehaxelt/Python-dsstore>") comment = "Python dsstore module <https://github.com/gehaxelt/Python-dsstore>")
) )
Maintainer: Bob Rudis <bob@rud.is> Maintainer: Bob Rudis <bob@rud.is>
Description: A thin wrapper around the 'Python' 'dsstore' module Description: A set of tools/methods and data that are geared towards the 'macOS'
<https://github.com/gehaxelt/Python-dsstore> by 'Sebastian Neef'. ecosystem.
URL: https://github.com/hrbrmstr/mactheknife URL: https://github.com/hrbrmstr/mactheknife
BugReports: https://github.com/hrbrmstr/mactheknife/issues BugReports: https://github.com/hrbrmstr/mactheknife/issues
SystemRequirements: Python SystemRequirements: Python

3
R/mactheknife-package.R

@ -1,7 +1,6 @@
#' Read 'macOS' .DS_Store' Files #' Read 'macOS' .DS_Store' Files
#' #'
#' A thin wrapper around the 'Python' 'dsstore' module #' A set of tools/methods and data that are geared towards the 'macOS' ecosystem.
#' <https://github.com/gehaxelt/Python-dsstore> by 'Sebastian Neef'.
#' #'
#' @md #' @md
#' @name mactheknife #' @name mactheknife

35
R/read-dsstore.R

@ -1,22 +1,49 @@
#' Read a `.DS_Store` file #' Read a `.DS_Store` from a file/URL
#' #'
#' @md #' @md
#' @param path a path to a valid `.DS_Store` file ([path.expand()] will be called) #' @param path a path to a valid `.DS_Store` file ([path.expand()] will be called) _or_
#' a link to an `http[s]` reachable `.DS_Store` file. If a URL, [download.file()]
#' will be used to retrieve the remote `.DS_Store` file (to reduce package
#' dependencies).
#' @return a character vector of filenames in the `.DS_Store` file or #' @return a character vector of filenames in the `.DS_Store` file or
#' a length 0 character vector if no parseable data was found #' a length 0 character vector if no parseable data was found
#' @export #' @export
#' @references A thin wrapper around the 'Python' 'dsstore' module <https://github.com/gehaxelt/Python-dsstore> by 'Sebastian Neef'.
#' @examples #' @examples
#' read_dsstore(system.file("extdat", "DS_Store.ctf", package = "mactheknife")) #' read_dsstore(system.file("extdat", "DS_Store.ctf", package = "mactheknife"))
read_dsstore <- function(path) { read_dsstore <- function(path) {
path_is_url <- FALSE
if (is_url(path)) {
path_is_url <- TRUE
remote_path <- path
path <- tempfile(fileext = ".dsstore.tmp")
on.exit(unlink(path))
ret <- download.file(remote_path, path, quiet = TRUE, mode = "wb")
if (ret != 0) {
warning(".DS_Store file not found at the provided URL.")
return(character())
}
}
stor_path <- path.expand(path) stor_path <- path.expand(path)
stor_path <- normalizePath(stor_path) stor_path <- normalizePath(stor_path)
if ((!path_is_url) & (!file.exists(stor_path))) {
warning(".DS_Store file not found at specified path.")
return(character())
}
fil <- os$open(stor_path, os$O_RDONLY) fil <- os$open(stor_path, os$O_RDONLY)
contents <- os$read(fil, as.integer(file.size(stor_path))) contents <- os$read(fil, as.integer(file.size(stor_path)))
os$close(fil) os$close(fil)
d <- dsstore$DS_Store(contents) d <- try(dsstore$DS_Store(contents), silent = TRUE)
if (inherits(d, "try-error")) {
warning("Not a valid .DS_Store file.")
return(character())
}
ds_fils <- d$traverse_root() ds_fils <- d$traverse_root()
@ -24,6 +51,6 @@ read_dsstore <- function(path) {
if (length(out) == 0) out <- character() if (length(out) == 0) out <- character()
out return(out)
} }

3
R/utils.R

@ -0,0 +1,3 @@
is_url <- function(path) {
grepl("^(http|ftp)s?://", path)
}

17
README.Rmd

@ -4,20 +4,19 @@ output: rmarkdown::github_document
# mactheknife # mactheknife
Read 'macOS' .DS_Store' Files Various 'macOS'-oriented Tools and Utilities
## Description ## Description
A thin wrapper around the 'Python' 'dsstore' module <https://github.com/gehaxelt/Python-dsstore> by 'Sebastian Neef'. A set of tools/methods and data that are geared towards the 'macOS' ecosystem.
## NOTE ## NOTE
- This may turn into a broader "macOS hacking" package
- Uses `reticulate` so a working Python implementation is needed - Uses `reticulate` so a working Python implementation is needed
## What's Inside The Tin ## What's Inside The Tin
- `read_dsstore`: Read a '.DS_Store' file - `read_dsstore`: Read a '.DS_Store' from a file/URL
The following functions are implemented: The following functions are implemented:
@ -41,7 +40,7 @@ packageVersion("mactheknife")
``` ```
## Built-in data ## `.DS_Store` example using built-in data
```{r} ```{r}
read_dsstore( read_dsstore(
@ -49,7 +48,13 @@ read_dsstore(
) )
``` ```
## My "~/projects" folder (use your own dir as an example) ## A URL I should not have let a `.DS_Store` file lying around in
```{r}
read_dsstore("https://rud.is/books/21-recipes/.DS_Store")
```
## `.DS_Store` larger example using my "~/projects" folder (use your own dir as an example)
```{r} ```{r}
library(magrittr) library(magrittr)

22
README.md

@ -1,21 +1,20 @@
# mactheknife # mactheknife
Read ‘macOS’ .DS\_Store’ Files Various ‘macOS’-oriented Tools and Utilities
## Description ## Description
A thin wrapper around the ‘Python’ ‘dsstore’ module A set of tools/methods and data that are geared towards the ‘macOS’
<https://github.com/gehaxelt/Python-dsstore> by ‘Sebastian Neef’. ecosystem.
## NOTE ## NOTE
- This may turn into a broader “macOS hacking” package
- Uses `reticulate` so a working Python implementation is needed - Uses `reticulate` so a working Python implementation is needed
## What’s Inside The Tin ## What’s Inside The Tin
- `read_dsstore`: Read a ‘.DS\_Store’ file - `read_dsstore`: Read a ‘.DS\_Store’ from a file/URL
The following functions are implemented: The following functions are implemented:
@ -36,7 +35,7 @@ packageVersion("mactheknife")
## [1] '0.1.0' ## [1] '0.1.0'
## Built-in data ## `.DS_Store` example using built-in data
``` r ``` r
read_dsstore( read_dsstore(
@ -46,7 +45,16 @@ read_dsstore(
## [1] "favicon.ico" "flag" "static" "templates" "vulnerable.py" "vulnerable.wsgi" ## [1] "favicon.ico" "flag" "static" "templates" "vulnerable.py" "vulnerable.wsgi"
## My “~/projects” folder (use your own dir as an example) ## A URL I should not have let a `.DS_Store` file lying around in
``` r
read_dsstore("https://rud.is/books/21-recipes/.DS_Store")
```
## [1] "06-Creating-a-Graph-of-Retweet-Relationships_files" "07-Visualizing-a-Graph-of-Retweet-Relationships_files"
## [3] "20-Visualizing-Geodata-with-a-Dorling-Cartogram_files" "libs"
## `.DS_Store` larger example using my “~/projects” folder (use your own dir as an example)
``` r ``` r
library(magrittr) library(magrittr)

3
man/mactheknife.Rd

@ -6,8 +6,7 @@
\alias{mactheknife-package} \alias{mactheknife-package}
\title{Read 'macOS' .DS_Store' Files} \title{Read 'macOS' .DS_Store' Files}
\description{ \description{
A thin wrapper around the 'Python' 'dsstore' module A set of tools/methods and data that are geared towards the 'macOS' ecosystem.
\url{https://github.com/gehaxelt/Python-dsstore} by 'Sebastian Neef'.
} }
\author{ \author{
Bob Rudis (bob@rud.is) Bob Rudis (bob@rud.is)

12
man/read_dsstore.Rd

@ -2,20 +2,26 @@
% Please edit documentation in R/read-dsstore.R % Please edit documentation in R/read-dsstore.R
\name{read_dsstore} \name{read_dsstore}
\alias{read_dsstore} \alias{read_dsstore}
\title{Read a \code{.DS_Store} file} \title{Read a \code{.DS_Store} from a file/URL}
\usage{ \usage{
read_dsstore(path) read_dsstore(path)
} }
\arguments{ \arguments{
\item{path}{a path to a valid \code{.DS_Store} file (\code{\link[=path.expand]{path.expand()}} will be called)} \item{path}{a path to a valid \code{.DS_Store} file (\code{\link[=path.expand]{path.expand()}} will be called) \emph{or}
a link to an \code{http[s]} reachable \code{.DS_Store} file. If a URL, \code{\link[=download.file]{download.file()}}
will be used to retrieve the remote \code{.DS_Store} file (to reduce package
dependencies).}
} }
\value{ \value{
a character vector of filenames in the \code{.DS_Store} file or a character vector of filenames in the \code{.DS_Store} file or
a length 0 character vector if no parseable data was found a length 0 character vector if no parseable data was found
} }
\description{ \description{
Read a \code{.DS_Store} file Read a \code{.DS_Store} from a file/URL
} }
\examples{ \examples{
read_dsstore(system.file("extdat", "DS_Store.ctf", package = "mactheknife")) read_dsstore(system.file("extdat", "DS_Store.ctf", package = "mactheknife"))
} }
\references{
A thin wrapper around the 'Python' 'dsstore' module \url{https://github.com/gehaxelt/Python-dsstore} by 'Sebastian Neef'.
}

Loading…
Cancel
Save