Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 247 lines (208 sloc) 4.97 KB
#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../perl-lib";
use Data::Dumper;
use Time::Local;
use SharePoint::Connection;
use SharePoint::CommandLine;
my %opts = SharePoint::CommandLine->get_options(
{
fields=>"",
list=>"",
view=>"",
where=>"",
item=>"",
group=>"",
url=>"",
title=>"",
},
{
"fields-file:s" => "fields",
"list:s" => "list",
"view:s" => "view",
"where:s" => "where",
"item:s" => "item",
"group:s" => "group",
"url:s" => "url",
"title:s" => "title",
}
);
my( $action ) = @ARGV;
if( !defined $action )
{
print STDERR usage();
die "No action specified";
}
binmode( STDOUT, ":utf8" );
$opts{"fields-list"} = [];
if( $opts{fields} ne "" )
{
open( F, $opts{fields} ) || die "can't read '$opts{fields}': $!";
while( my $line = <F> )
{
chomp $line;
push @{$opts{"fields-list"}}, $line;
}
close F;
}
my $spc = new SharePoint::Connection( %opts );
if( $action eq "list-to-tsv" )
{
action_list_to_tsv( $spc, %opts );
}
elsif( $action eq "list-dump" )
{
action_list_dump( $spc, %opts );
}
elsif( $action eq "calendar-to-ical" )
{
action_calendar_to_ical( $spc, %opts );
}
elsif( $action eq "collections" )
{
action_collections( $spc, %opts );
}
elsif( $action eq "webs" )
{
action_webs( $spc, %opts );
}
elsif( $action eq "list-info" )
{
action_list_info( $spc, %opts );
}
elsif( $action eq "list-fields" )
{
action_list_fields( $spc, %opts );
}
elsif( $action eq "get-item" )
{
action_get_item( $spc, %opts );
}
elsif( $action eq "attachment-collection" )
{
action_attachment_collection( $spc, %opts );
}
elsif( $action eq "group-collection" )
{
action_group_collection( $spc, %opts );
}
elsif( $action eq "group-members" )
{
action_group_members( $spc, %opts );
}
else
{
print STDERR "Unknown action: $action\n\n";
print STDERR usage();
exit 1;
}
exit;
sub usage
{
return <<END
All commands also require --credentials
shareperltopus collections --site <site-url>
shareperltopus webs --site <site-url>
shareperltopus list-info --site <site-url> --list <list-id>
shareperltopus list-dump --site <site-url> --list <list-id> [--view <view>]
shareperltopus list-fields --site <site-url> --list <list-id>
shareperltopus list-to-tsv --site <site-url> --list <list-id> [--fields-file <file>] [--view <view>] [--where <where>]
shareperltopus calendar-to-ical --site <site-url> --list <list-id> [--view <view>] [--title <title>] [--where <where>]
shareperltopus group-collection --site <site-url>
shareperltopus group-members --site <site-url> --group <group-name>
END
}
sub action_list_info
{
my( $spc, %opts ) = @_;
if( $opts{list} eq "" ) { die "list-to-tsv needs --list to be set"; }
my $map = {};
my $listinfo = $spc->GetList( $opts{list} );
print Dumper( $listinfo );
}
sub action_group_collection
{
my( $spc, %opts ) = @_;
my @result = $spc->GetGroupCollectionFromSite();
foreach my $data ( sort { $a->{ID} <=> $b->{ID} } @result)
{
print $data->{ID}." - ".$data->{Name}."\n";
}
}
sub action_group_members
{
my( $spc, %opts ) = @_;
if( $opts{group} eq "" ) { die "group-members needs --group to be set"; }
my @result = $spc->GetUserCollectionFromGroup( $opts{group} );
foreach my $data ( @result)
{
print $data->{LoginName}." - ".$data->{Email}." - ".$data->{Name}."\n";
}
}
sub action_collections
{
my( $spc, %opts ) = @_;
my @result = $spc->GetListCollection();
foreach my $data ( @result )
{
print $data->{ID}." - ".$data->{Title}."\n";
}
}
sub action_webs
{
my( $spc, %opts ) = @_;
my @result = $spc->GetWebCollection();
foreach my $data ( @result )
{
print $data->{Url}." - ".$data->{Title}."\n";
}
}
sub action_get_item
{
my( $spc, %opts ) = @_;
if( $opts{url} eq "" ) { die "attachment-collection needs --url to be set"; }
my $item = $spc->GetItem( $opts{url} );
print $item;
}
sub action_attachment_collection
{
my( $spc, %opts ) = @_;
if( $opts{list} eq "" ) { die "attachment-collection needs --list to be set"; }
if( $opts{item} eq "" ) { die "attachment-collection needs --item to be set"; }
my $map = {};
my $listinfo = $spc->GetAttachmentCollection( $opts{list}, $opts{item} );
}
sub action_list_fields
{
my( $spc, %opts ) = @_;
if( $opts{list} eq "" ) { die "list-fields needs --list to be set"; }
my $map = {};
my $listinfo = spc->GetList( $opts{list} );
foreach my $field ( @{$listinfo->{fields}} )
{
print sprintf( "%34s: %s\n", $field->{StaticName}, $field->{DisplayName} );
}
}
sub action_list_dump
{
my( $spc, %opts ) = @_;
if( $opts{list} eq "" ) { die "list-to-tsv needs --list to be set"; }
my $map = {};
if( $opts{view} eq "" ) { delete $opts{view}; }
my @items = $spc->GetListItems( $opts{list}, $opts{view} );
print Dumper(\@items);
}
sub action_list_to_tsv
{
my( $spc, %opts ) = @_;
if( $opts{list} eq "" ) { die "list-to-tsv needs --list to be set"; }
print $spc->ListAsTSV( %opts );
}
sub action_calendar_to_ical
{
my( $spc, %opts ) = @_;
if( $opts{list} eq "" ) { die "list_to_tsv needs --list to be set"; }
print $spc->CalendarAsICAL( %opts );
}