/extra/update/util/util.factor

http://github.com/abeaumont/factor · Factor · 62 lines · 39 code · 17 blank · 6 comment · 2 complexity · f26a179260cde0e995a64f8334bba89f MD5 · raw file

  1. USING: kernel classes strings quotations words math math.parser arrays
  2. combinators.smart
  3. accessors
  4. system prettyprint splitting
  5. sequences combinators sequences.deep
  6. io
  7. io.launcher
  8. io.encodings.utf8
  9. calendar
  10. calendar.format ;
  11. IN: update.util
  12. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  13. DEFER: to-strings
  14. : to-string ( obj -- str )
  15. dup class-of
  16. {
  17. { \ string [ ] }
  18. { \ quotation [ call( -- string ) ] }
  19. { \ word [ execute( -- string ) ] }
  20. { \ fixnum [ number>string ] }
  21. { \ array [ to-strings concat ] }
  22. }
  23. case ;
  24. : to-strings ( seq -- str )
  25. dup [ string? ] all?
  26. [ ]
  27. [ [ to-string ] map flatten ]
  28. if ;
  29. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  30. : cpu- ( -- cpu ) cpu unparse "." split "-" join ;
  31. : platform ( -- string ) { [ os unparse ] cpu- } to-strings "-" join ;
  32. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  33. : branch-name ( -- string ) "clean-" platform append ;
  34. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  35. : gnu-make ( -- string )
  36. "make" ;
  37. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  38. : git-id ( -- id )
  39. { "git" "show" } utf8 <process-reader> [ readln ] with-input-stream
  40. " " split second ;
  41. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  42. : datestamp ( -- string )
  43. now
  44. [ { [ year>> ] [ month>> ] [ day>> ] [ hour>> ] [ minute>> ] } cleave ] output>array
  45. [ pad-00 ] map "-" join ;