5

If I'm given a paclet server, "http://paclet.serv.er/" how can I determine what paclets are on it to install?

E.g. how could I find all of the ServiceConnections on this server: "http://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"?

b3m2a1
  • 46,870
  • 3
  • 92
  • 239

1 Answers1

6

The paclet data resides in a compressed file called PacletSite.mz". So we can import all of the paclets like so:

getPacletSiteData[server_] :=
  Block[
   {
    $Context = "PacletManager`Private`",
    $ContextPath = $ContextPath
    },
   ReplaceAll[
    Import[
     URLBuild@{server, "PacletSite.mz"},
     {"ZIP", "PacletSite.m"}
     ],
    (s_Symbol -> v_) :>
     (SymbolName[s] -> v)
    ]
   ];

Then to get the service connection we'll just implement a little name-based selector:

selectByName[PacletSite[p__], pat_] :=
 Pick[
  {p},
  StringMatchQ[pat]@
   Lookup[
    List @@@ {p},
    "Name"
    ]
  ]

And then running that we get the following:

paclets = 
  getPacletSiteData[
   "http://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"];

conns =
 selectByName[paclets, "ServiceConnection_*"] // 
  DeleteDuplicatesBy[#["Name"] &]

{
   Paclet["ServiceConnection_DeckOfCards","1.0.2",<>],
   Paclet["ServiceConnection_NASA","1.0.1",<>],
   Paclet["ServiceConnection_StackExchange","1.1.6",<>],
   Paclet["ServiceConnection_WolframCommunity","1.0.3",<>],
   Paclet["ServiceConnection_GitHub","1.0.3",<>],
   Paclet["ServiceConnection_GoogleDrive","1.0.2",<>],
   Paclet["ServiceConnection_Qwant","1.0.5",<>],
   Paclet["ServiceConnection_Git","1.0.0",<>],
   Paclet["ServiceConnection_GitHubJobs","1.0.0",<>]
   } 

You could then install any of these like so:

pac = RandomChoice[conns]["Name"]

"ServiceConnection_GitHubJobs"

PacletInstall[pac,
 "Site" ->
  "http://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"
 ]

rara

b3m2a1
  • 46,870
  • 3
  • 92
  • 239