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