source: subversion/applications/utils/revert/Changeset.pm @ 17935

Last change on this file since 17935 was 17430, checked in by frederik, 10 years ago

fix parameter number bug

  • Property svn:keywords set to Revision
File size: 2.1 KB
Line 
1#!/usr/bin/perl
2
3# Changeset.pm
4# ------------
5#
6# Implements changeset operations on the OSM API
7#
8# Part of the "osmtools" suite of programs
9# Originally written by Frederik Ramm <frederik@remote.org>; public domain
10
11package Changeset;
12
13use strict;
14use warnings;
15use OsmApi;
16
17# Creates new changeset.
18# Parameters: none
19# Returns: changeset id, or undef in case of error (will write error to stderr)
20
21sub create
22{
23    my $comment = shift;
24    $comment = (defined($comment)) ? "<tag k=\"comment\" v=\"$comment\" />" : "";
25    my $resp = OsmApi::put("changeset/create", "<osm version='0.6'><changeset>$comment</changeset></osm>");
26    if (!$resp->is_success)
27    {
28        print STDERR "cannot create changeset: ".$resp->status_line."\n";
29        return undef;
30    }
31    return $resp->content();
32}
33
34# Closes changeset.
35# Parameters: changeset id, commit comment
36# Returns: 1=success undef=error (will write error to stderr)
37
38sub close($$)
39{
40    my ($id, $comment) = @_;
41    $comment =~ s/&/&amp;/g;
42    $comment =~ s/</&lt;/g;
43    $comment =~ s/>/&gt;/g;
44    $comment =~ s/"/&quot;/g;
45
46    my $revision = '$Revision: 17430 $';
47    my $revno = 0;
48    $revno = $1 if ($revision =~ /:\s*(\d+)/);
49
50    my $resp = OsmApi::put("changeset/$id", <<EOF);
51<osm version='0.6'>
52<changeset>
53<tag k='comment' v=\"$comment\" />
54<tag k='created_by' v='osmtools/$revno ($^O)' />
55</changeset>
56</osm>
57EOF
58    if (!$resp->is_success)
59    {
60        print STDERR "cannot update changeset: ".$resp->status_line."\n";
61        return undef;
62    }
63    $resp = OsmApi::put("changeset/$id/close");
64    if (!$resp->is_success)
65    {
66        print STDERR "cannot close changeset: ".$resp->status_line."\n";
67        return undef;
68    }
69    return 1;
70}
71
72sub upload($$)
73{
74    my ($id, $content) = @_;
75    OsmApi::set_timeout(7200);
76    $content =~ s/changeset="[^"]*"/changeset="$id"/g;
77    my $resp = OsmApi::post("changeset/$id/upload", $content);
78
79    if (!$resp->is_success)
80    {
81        print STDERR "cannot upload changeset: ".$resp->status_line."\n";
82        print STDERR $resp->content;
83        return undef;
84    }
85    return 1;
86}
87
881;
Note: See TracBrowser for help on using the repository browser.