3

规定:令人惊叹的etherpad最近开源了。在这里获取:http ://code.google.com/p/etherpad 。这是我在 StackOverflow 上知道的关于 etherpad 代码的第一个问题。如果您是 etherpad 开源社区的一员,您可能希望订阅RSS 提要以获取标记为“etherpad”的问题,以防万一!

我的实际问题,假设您在自己的服务器上安装了 etherpad:

首先,这是一个查看最近编辑的 pad 的查询:

SELECT id,lastWriteTime,creationTime,headRev 
  FROM PAD_SQLMETA ORDER BY lastWriteTime, headRev;

或者,如果您想从 unix 提示符运行它:

mysql -u root -pPASSWD etherpad -e "select id,lastWriteTime,creationTime,headRev 
  from PAD_SQLMETA order by lastWriteTime, headRev"

这很方便,但lastWriteTime实际上每次有人在浏览器中查看平板电脑时都会更新。我宁愿按它们最后一次编辑的时间对它们进行排序。可能有一个花哨的 SQL 查询涉及与另一个表的连接,该表将显示实际的上次编辑时间。有谁知道那是什么?或者,您可以有一个脚本来通知 headRev 何时发生变化,但这似乎不是最干净的方法。

4

1 回答 1

1

我还没有完全弄清楚我原来的问题的答案,但我写了一个脚本来实现类似的东西。它的主要目的是导出我所有垫子的纯文本版本并将它们存储在我的笔记本电脑上。作为副作用,它向我显示了哪些焊盘发生了变化,并让我看到了自上次导出版本以来的差异。它还显示了哪些是新创建的。

首先,在托管您的 etherpad 实例的服务器上创建以下脚本padlist.pl

#!/usr/bin/env perl

$list = `mysql -u root -pPASSWD etherpad -e 
         "select id from PAD_SQLMETA order by lastWriteTime DESC, headRev DESC"`;

$list =~ s/^id\s*\n//s;  # get rid of the column header mysql adds.
print $list;

fetchall.pl然后在您的本地计算机上运行以下脚本。它会收集你所有打击垫的快照,并告诉你哪些已经改变,哪些是新出现的。

#!/usr/bin/env perl

use LWP::Simple qw(get);
$| = 1;  # autoflush.
$server = "server.com"; # the server that hosts your etherpad instance.

$pads = `ssh $server etherpad/padlist.pl`;
@padlist = split(/\s+/, $pads);

$neednewline = 0; # printing "." for each pad where nothing to be done.
for(@padlist) {
  $ep = $_;
  $localfile = "$ep.txt";
  if(-e $localfile) { 
    $localexists = 1; 
    $localcontent = do {local (@ARGV,$/) = $localfile; <>};
  } else { $localexists = 0; }
  $livecontent = get("http://$server/ep/pad/export/$ep/latest?format=txt");
  if($livecontent ne $localcontent) {
    if($neednewline) { print "\n";  $neednewline = 0; }
    if($localexists) { 
      print "CHANGED: $ep\n"; 
      open(F, ">prev/$localfile") or die "Probably need to create 'prev' dir.";
      print F $localcontent;
      close(F);
    } else { print "NEW:     $ep\n"; }
    open(F, ">$localfile") or die;
    print F $livecontent;
    close(F);
  } else {
    print ".";
    $neednewline = 1;
} }

要查看自上次获取 pad foo 以来的差异:

diff prev/foo.txt foo.txt
于 2010-05-27T21:07:26.030 回答