mps.ex 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. defmodule Mps do
  2. @moduledoc """
  3. Milis Paket Sistemi
  4. """
  5. @doc """
  6. Mps hakkında bilgi verir.
  7. iex> Mps.nedir
  8. """
  9. def nedir do
  10. "MPS Milis Linux için yazılmış paket yönetim uygulamasıdır. Bu konsol, Elixir dilinde üst seviye etkileşim sağlamak için geliştirilmektedir."
  11. end
  12. @doc """
  13. ilgili talimat hakkında bilgi verir.
  14. iex> Mps.bilgi talimat_ismi
  15. """
  16. def bilgi(talimat) do
  17. case File.read(talimat) do
  18. {:ok, context} -> context
  19. {:error, reason} -> reason
  20. end
  21. end
  22. def parse_talimat(talimat,key \\ "Gerekler") do
  23. IO.puts "..." <> talimat
  24. Enum.map(read_talimat(talimat), \
  25. fn (lines) -> if String.contains?(lines, key), \
  26. do: String.split(lines, ":", trim: true) |> tl end)
  27. |> Enum.filter(& !is_nil(&1)) |> hd
  28. |> (fn (list) -> if Enum.empty?(list), \
  29. do: [], else: \
  30. list |> hd |> String.replace(","," ") |> String.split end).()
  31. end
  32. def deps(talimat) do
  33. unless :ets.info(:deps) == :undefined , do: :ets.delete(:deps)
  34. #:ets.delete_all_objects(:deps)
  35. talimat |> find_deps_chain
  36. end
  37. defp find_deps_chain(talimat) do
  38. if :ets.info(:deps) == :undefined, do: :ets.new(:deps, [:bag, :set, :public, :named_table])
  39. #unless :ets.member(:deps,talimat) do
  40. if :ets.match(:deps, {:"$1", talimat}) == [] do
  41. depends=talimat
  42. |> parse_talimat
  43. talimat |> add_dep
  44. depends |> Enum.map(&find_deps_chain/1)
  45. end
  46. #:ets.tab2list(:deps)
  47. #for {pkt} <- :ets.tab2list(:deps) ,do: pkt
  48. for {durum,pkt} <- :ets.tab2list(:deps) ,do: [durum,pkt]
  49. end
  50. defp add_dep(talimat) do
  51. #:ets.insert(:deps,{talimat})
  52. case talimat |> kurulu? do
  53. true -> :ets.insert(:deps,{"kurulu", talimat})
  54. false -> :ets.insert(:deps,{"degil", talimat})
  55. end
  56. #IO.puts "..." <> talimat
  57. end
  58. def read_talimat(talimat) do
  59. talimat
  60. |> find_talimat
  61. |> File.stream!
  62. |> Stream.map(&String.trim_trailing/1)
  63. |> Enum.to_list
  64. end
  65. def kurulu?(paket) do
  66. db="/var/lib/pkg/DB"
  67. File.exists?(db <> "/" <> paket)
  68. end
  69. def talimatlar() do
  70. Path.wildcard("/root/talimatname/genel/*/*/talimat") |> Enum.map(&Path.dirname(&1)) |> Enum.map(&Path.basename(&1))
  71. end
  72. def find_talimat(talimat) do
  73. (Path.wildcard("/root/talimatname/**/" <> talimat) |> hd) <> "/talimat"
  74. end
  75. def bul(talimat) do
  76. talimatname_genel="/root/talimatname/genel"
  77. talimatname_genel <> "/" <> String.at(talimat,0) <> "/" <> talimat <> "/" <> "talimat" |> File.read!
  78. end
  79. end
  80. #Enum.map(lines,depends_control(lines))
  81. #Enum.map(lines,packager_control(lines))
  82. #|> Enum.map(&depends_control(&1))
  83. #|> Enum.map(&packager_control(&1))
  84. # |> Enum.filter(& !is_nil(&1))
  85. # |> Enum.filter(fn(x) -> if String.contains?(x, ["#"]), do: "found: #{x}", else: "not found" end)
  86. # |> Enum.filter(fn(x) -> if String.contains?(x, ["foo"]), do: x, else: "not found" end)
  87. # Enum.each(seasons, &IO.puts/1)
  88. # |> Stream.map(fn ({line, index}) -> IO.puts "#{index + 1} #{line}" end)
  89. # |> Stream.map(fn (line) -> IO.puts "#{line}" end)
  90. # do: IO.puts("|_" <> talimat) , else: list |> Enum.each(fn x -> {IO.puts("*" <> x <> "*"), find_deps(x)} end) end).()