PageRenderTime 115ms CodeModel.GetById 93ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 1ms

/extra/update/util/util.factor

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