talimatname_indeks_yap 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #!/usr/bin/perl -w
  2. our $version = "1.0.4";
  3. ########################################################################
  4. #
  5. # portspage (http://www.karsikkopuu.net/crux/scripts/)
  6. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #
  8. # 2017 milis linux talimatnamesine uyarlama - milisarge
  9. ########################################################################
  10. use strict;
  11. our %options =
  12. (
  13. title => "Milis Linux Talimatnamesi",
  14. timestamp_accuracy => 1,
  15. date_from_file => 0,
  16. );
  17. sub print_usage
  18. {
  19. print <<EOT;
  20. Usage: talimatname_indeks_yap [paremetre]... [dizin]
  21. --title=TITLE set the page title
  22. --header=FILE name of file to insert before port listing
  23. --footer=FILE name of file to insert after port listing
  24. --timestamp-accuracy=LEVEL 0 = no timestamp, 1 = date only, 2 = date and time
  25. default is 1
  26. --date-from-file take date from newest file instead of directory
  27. --date-from-pkgfile take date from Pkgfile instead of directory
  28. --version output version information and exit
  29. EOT
  30. }
  31. sub parse_args
  32. {
  33. foreach my $arg (@ARGV)
  34. {
  35. if ($arg =~ /^--header=(.*)$/)
  36. {
  37. $options{header} = $1;
  38. }
  39. elsif ($arg =~ /^--footer=(.*)$/)
  40. {
  41. $options{footer} = $1;
  42. }
  43. elsif ($arg =~ /^--title=(.*)$/)
  44. {
  45. $options{title} = $1;
  46. }
  47. elsif ($arg =~ /^--timestamp-accuracy=(0|1|2)$/)
  48. {
  49. $options{timestamp_accuracy} = $1;
  50. }
  51. elsif ($arg =~ /^--date-from-file$/)
  52. {
  53. $options{date_from_file} = 1;
  54. }
  55. elsif ($arg =~ /^--date-from-pkgfile$/)
  56. {
  57. $options{date_from_pkgfile} = 1;
  58. }
  59. elsif ($arg =~ /^--version$/)
  60. {
  61. print "$version\n";
  62. exit 0;
  63. }
  64. elsif ($arg =~ /^--help$/)
  65. {
  66. print_usage();
  67. exit 0;
  68. }
  69. else
  70. {
  71. $options{directory} = $arg;
  72. }
  73. }
  74. }
  75. sub recurse_tree
  76. {
  77. my $path = shift;
  78. my @list;
  79. while ($path =~ s/\/\//\//g) {}
  80. $path =~ s/\/$//;
  81. opendir(DIR, $path) or return;
  82. ENTRY:
  83. foreach my $entry(sort(readdir(DIR)))
  84. {
  85. next ENTRY if $entry eq ".";
  86. next ENTRY if $entry eq "..";
  87. push (@list, "$path/$entry") if -f "$path/$entry";
  88. push (@list, recurse_tree("$path/$entry")) if -d "$path/$entry";
  89. }
  90. return @list;
  91. }
  92. sub parse_pkgfile
  93. {
  94. my %parsed;
  95. my $pkgfile = shift;
  96. if (open (FILE, $pkgfile))
  97. {
  98. while (<FILE>)
  99. {
  100. if ($_ =~ /^#\s*(.*?):\s*(.*)$/)
  101. {
  102. my $key = $1;
  103. my $value = $2;
  104. $value =~ s/</&lt;/g;
  105. $value =~ s/>/&gt;/g;
  106. $value =~ s/&/&amp;/g;
  107. $parsed{$key} = $value;
  108. }
  109. elsif ($_ =~ /^version=(.*)$/)
  110. {
  111. $parsed{version} = $1;
  112. }
  113. elsif ($_ =~ /^release=(.*)$/)
  114. {
  115. $parsed{release} = $1;
  116. }
  117. }
  118. close (FILE);
  119. }
  120. return { %parsed };
  121. }
  122. sub main
  123. {
  124. my %db;
  125. parse_args();
  126. if (!$options{directory})
  127. {
  128. print_usage();
  129. return 0;
  130. }
  131. foreach my $file (recurse_tree($options{directory}))
  132. {
  133. if ($file =~ q:.*/(.*)/talimat$:)
  134. {
  135. $db{$1} = parse_pkgfile("$file");
  136. }
  137. }
  138. print <<EOH;
  139. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  140. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  141. <html xml:lang="tr" lang="tr" xmlns="http://www.w3.org/1999/xhtml">
  142. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  143. <head>
  144. <meta http-equiv="content-type" contentType="text/html;">
  145. EOH
  146. print " <title>$options{title}</title>\n";
  147. print <<EOH;
  148. <style type="text/css">
  149. body
  150. {
  151. font-family: Verdana, sans-serif;
  152. font-size: 85%;
  153. padding: 2em;
  154. }
  155. a
  156. {
  157. color: black;
  158. }
  159. table
  160. {
  161. border: solid #CAD4E9 1px;
  162. font-size: 85%;
  163. }
  164. td
  165. {
  166. padding: 6px;
  167. }
  168. tr.header
  169. {
  170. background-color: #CAD4E9;
  171. }
  172. tr.odd
  173. {
  174. background-color: #ECF0F7;
  175. }
  176. tr.even
  177. {
  178. background-color: #F7F9FC;
  179. }
  180. </style>
  181. </head>
  182. <body>
  183. EOH
  184. print " <h2>$options{title}</h2>\n";
  185. if ($options{header})
  186. {
  187. open(FILE, $options{header}) or die "Couldn't open header file";
  188. while (<FILE>)
  189. {
  190. print " " . $_;
  191. }
  192. close(FILE);
  193. }
  194. print " <table width=\"100%\" cellspacing=\"0\">\n";
  195. print " <tr class=\"header\"><td><b>Talimat</b></td><td><b>Sürüm</b></td><td><b>Açıklama</b></td>";
  196. if ($options{timestamp_accuracy} > 0)
  197. {
  198. print "<td><b>Son değişiklik</b></td>";
  199. }
  200. print "</tr>\n";
  201. our $odd = "odd";
  202. my $count = 0;
  203. foreach my $port (sort keys %db)
  204. {
  205. $count++;
  206. print " <tr class=\"$odd\"><td>";
  207. $db{$port}{URL} ? print "<a href=\"$db{$port}{URL}\">$port</a>" : print "$port";
  208. print "</td><td><a href=\"$options{directory}/$port/\">$db{$port}{version}-$db{$port}{release}</a></td><td>";
  209. print $db{$port}{Description} if $db{$port}{Description};
  210. print "</td>";
  211. if ($options{timestamp_accuracy} > 0)
  212. {
  213. my $date;
  214. if ($options{date_from_file})
  215. {
  216. my @files = recurse_tree("$options{directory}/$port");
  217. my @dates;
  218. foreach my $file (@files)
  219. {
  220. push (@dates, (stat($file))[9]);
  221. }
  222. @dates = sort @dates;
  223. $date = $dates[$#dates];
  224. }
  225. elsif ($options{date_from_pkgfile})
  226. {
  227. $date = (stat("$options{directory}/$port/talimat"))[9];
  228. }
  229. else
  230. {
  231. $date = (stat("$options{directory}/$port"))[9];
  232. }
  233. print "<td>" . isotime($date, $options{timestamp_accuracy}) . "</td>";
  234. }
  235. print "</tr>\n";
  236. if ($odd eq "odd") { $odd = "even"; }
  237. else { $odd = "odd"; }
  238. }
  239. print " </table>\n";
  240. print " <p><b>$count ports</b></p>\n";
  241. if ($options{footer})
  242. {
  243. open(FILE, $options{footer}) or die "Couldn't open footer file";
  244. while (<FILE>)
  245. {
  246. print " " . $_;
  247. }
  248. close(FILE);
  249. }
  250. print <<EOH;
  251. </body>
  252. </html>
  253. EOH
  254. return 0;
  255. }
  256. sub isotime
  257. {
  258. my $time = (shift or time);
  259. my $accuracy = (shift or 2);
  260. my @t = gmtime ($time);
  261. my $year = $t[5] + 1900;
  262. my $month = sprintf("%02d", $t[4] + 1);
  263. my $day = sprintf("%02d", $t[3]);
  264. if ($accuracy == 1)
  265. {
  266. return "$year-$month-$day";
  267. }
  268. return "$year-$month-$day " . sprintf("%02d:%02d:%02d UTC", $t[2], $t[1], $t[0]);
  269. }
  270. exit(main());
  271. # End of file