#!/usr/bin/perl
# 
# script:	upstream2mysql
# license:	GPL v2 or later
# description:	This scripts process parameters from debian/watch files
#		and analogs. Output - the url of upstream tarball.
#		It's mainly ported uscan.pl script from devscript package (debian)
#		We have to run debwatch2mysql before this script to add urls to db.
# authors:	
# 		Originally written by Christoph Lameter <clameter@debian.org> (I believe)
# 		Modified by Julian Gilbey <jdg@debian.org>
# 		HTTP support added by Piotr Roszatycki <dexter@debian.org>
# 		Rewritten in Perl, Copyright 2002-2006, Julian Gilbey
#
#		Ported to ALT Linux distribution by Andrew Avramenko <liks@altlinux.ru> 

# TODO
# It's a long list what we can do here. First of all we have to review code. Some parts of
# it I simply commented because it isn't useful for me.

#use Getopt::Long;
#use File::Basename;
use DBI;
use lib "/home/liks/scripts";
use upstreamwatch;

require 'config';

my $upstreamwath = new upstreamwatch;

#> Connect to mysql
my $dbh = DBI->connect($dsn,$dbUser,$dbPass);
my $sth = $dbh->prepare("SELECT * FROM watch");
$sth->execute();

my $sth2 = $dbh->prepare("REPLACE other VALUES(?,?,?,?)");
$a = 0;
#> Processing watch line for each srpm
while (@row=$sth->fetchrow_array()) {
#	print "$row[0]\n";

#> If we want to start from specific package we have just uncomment 2 lines bellow
#	if ($row[0] eq "poedit") {$a = 1; next;}
#	next if ($a == 0); 
	($url,$version) = upstreamwatch::process_watchline($row[1],$row[2],$row[0]);
	print "url=$url   version=$version\n";
	if ((defined($url)) && (defined($version))) {
	    $sth2->execute($row[0],$version,"upstream",$url);
	}
}

#> Close connection to mysql
$sth->finish();
$sth2->finish();
$dbh->disconnect;

