Difference between revisions of "Describe all packages/Source Code"

From SimsWiki
Jump to: navigation, search
(First version)
 
m
 
Line 7: Line 7:
 
=Source=
 
=Source=
  
In order to run this function, the user must load (using the "source" function) the script in [[Editing Detect Pets Body Shop bug/Source Code]].
+
In order to run this function, the user must load (using the "source" function) the script in [[Detect Pets Body Shop bug/Source Code]].
  
 
<pre>
 
<pre>

Latest revision as of 14:41, 20 July 2008

[edit] Overview

This page contains a code in R that describes (in a human-readable, text list) all packages.

Use at your own risk. Any comments please use the Talk:Describe all packages/Source Code page.

[edit] Source

In order to run this function, the user must load (using the "source" function) the script in Detect Pets Body Shop bug/Source Code.


#
# The next routine opens _all_ package files since
# some date and displays package name and description
# start_date must be passed as an ISO-8601 string.
#
describe_all_packages <- function(start_date = "2005-01-01")
{
  # create vector with all filenames that end in .package
  item_list <- c("category", "age", "gender", "outfit")
  s_date <- as.POSIXlt(start_date, "GMT")
  fnlist <- list.files(pattern = ".package$") 
  cat("item_list = (", item_list, ")\n")
  for (i in 1:length(fnlist)) {
    filename <- fnlist[i]
    # get modification time of package
    m_date  <- as.POSIXlt(file.info(filename)$mtime, "GMT")
    # skip if package is older than start date
    if (m_date < s_date)
      next  # in C or similar languages, this would be a continue
    # now let's do the hard work
    x <- try(read_package(filename, get.str = T, get.everything = F))
    # there should be some sanity checks here!
    if (is.null(x)) {
      cat(filename, "seems to have another error\n")
      next
    }
    if (is.null(x$files)) next
    cat(filename, " ")
    if (!is.null(x$property.set) & !is.null(x$property.set$human)) {
      prop <- ""
      for (item in item_list) {
        if (!is.null(x$property.set$human[[item]]))
          prop <- sprintf("%s %s=%X", prop, item, x$property.set$human[[item]])
      }
      cat("(", prop, " ) ", sep="")
    }
    for (i in 1:length(x$files)) {
      if (x$index[[i]]$type.id == "53545223") {
        cat(x$files[[i]]$human, " ")
      }
    }
    cat("\n")
  }
  # done
  cat("Total of", length(fnlist), "files processed\n")
}


[edit] See Also

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox