How to use bugzilla API in existing bugzilla code? - perl

Well, at the moment i have two goals.
User don't have Edit bug rights in bugzilla, but he/she should write/post comments on that bug. I think this could be possible by the following API, but I am not sure, since I am new in bugzilla and Perl. http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#add_comment
I want to import bugs by using importxml.pl, but I don't want new entries in DB. I just want to modify some fields of existing bugs of bugzilla, on the base of bug.xml file which contains bug info.
i.e. perl -T C:\bugzilla\bugzilla\importxml.pl -v C:\bugzilla\bugzilla\mybugs\bug.xml
Might be following API could be helpful, but I am not sure.
http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#update
So, what are possible ways to achieve these goals ??
As I am thinking, may be i should use the methods of these APIs into existing bugzilla code and my dreams are:
comments would be enabled for the user who don't have bug-edit right.
I'll run the importxml.pl script from command line by passing some parameters and I'll modify some fields of existing bugs.
But I am not sure, either I am thinking right or wrong. I also don't know how to use the method of these APIs??

The email_in.pl script can do the types of things you are asking. However, you will need to create a user that does have permissions to make the changes and you will need to transform the data into a form that email_in.pl understands.
http://www.bugzilla.org/docs/4.2/en/html/api/email_in.html

I can help with the first point:
Here's an excerpt from a a svn_bz_append.pl script (http://www.telegraphics.com.au/svn/svn_bz/trunk/) that I've modified that I use to update bugzilla comments on svn commits. Note that I have this script running on the same machine as the Bugzilla install, as it uses modules from within the Bugzilla directory. I have this working for Bugzilla v 4.2.3.
I've omitted quite a bit of this script to pull out the excerpt below:
use strict;
use warnings;
use Bugzilla;
use Bugzilla::Config;
use Bugzilla::Bug;
use Data::Dumper;
... create/fetch the userid and some bug Ids to work on ...
eg:
my $userid = 1;
my #bugs = ( 1, 2, 3 );
my $message = 'Say something here';
... now loop through the bug ids and add the comment...
foreach my $bugId (#bugs) {
my $user = new Bugzilla::User({ id => $userid})
|| ThrowUserError('invalid_username', { id => $userid}); #get the user from bugzilla
print STDERR 'user: '. Dumper($user); #pretty prints the user object
Bugzilla->set_user($user); #this authenticates the user so that you may perform actions on bugs that the user has permissions to.
my $bug = Bugzilla::Bug->check($bugId); #gets the bug
print STDERR 'bug: '. Dumper($bug); #pretty prints the bug object
$bug->add_comment($message); #adds a comment to the bug
$bug->update(); #updated the bug - don't forget to do this!
}
Please note that the Dumper functions are just using the excellent Data::Dumper module: http://perldoc.perl.org/Data/Dumper.html - you don't need them except for debugging.
The log in info came from: How can I authenticate when using the Bugzilla Perl API in a script?

Related

How to mark mails in Gmail as 'read' and Delete them using Mail::Webmail::Gmail, using Perl script?

Using Perl , I need to read mails in Gmail, mark them as 'read' and delete them.
I have tried the below code as given in http://search.cpan.org/dist/Mail-Webmail-Gmail/lib/Mail/Webmail/Gmail.pm
use Mail::Webmail::Gmail;
use Data::Dumper;
my $gmail = Mail::Webmail::Gmail->new(
username => 'user#gmail.com', password => 'password',
);
print Dumper $gmail;
my #labels = $gmail->get_labels();
print Dumper #labels;
my $messages = $gmail->get_messages( label => $labels[0] );
print Dumper $messages;
Not able to get the labels, messages.
What is missing here ?
Is there any other way I could achieve these tasks in Perl.
Thanks in advance.
Subhash
That module was last updated in 2006 and the documentation says:
Because Gmail is currently in Beta testing, expect this module to break as they make updates to thier interface. I will attempt to keep this module in line with the changes they make, but, if after updating to the newest version of this module, the feature that you require still doesn't work, please contact me with the issue.
You could try contacting the author, but with ten years since the last release, it looks like he lost interest.
But GMail has an IMAP interface. So you should be able to do what you want with a module like Mail::IMAPClient.

Perl: How to retrieve album metadata from MusicBrainz?

I am creating a Perl script which will move a mp3 file to my music folder in format artist/album/mp3file. Now it is possible that some of my mp3 files don't have an album tag so I thought of querying the MusicBrainz database to retrieve album metadata given track title & artist.
I am using WebService::MusicBrainz Perl module for this task, but I am not able to see any method that gives album metadata info. My current code is:
use WebService::MusicBrainz::Track;
my $ws = WebService::MusicBrainz::Track->new();
my $response = $ws->search({ ARTIST => 'Ryan Adams', TITLE => 'when the stars go blue' });
my $track = $response->track();
print $track->title(), " - ", $track->artist()->name(), "\n";
say $track->id();
So, how do I get my the album info for a given track using MusicBrainz and if it is not possible what are my alternative options?
First of all, what you want is adding metadata to mp3s which is the most common usage scenario people have. The "normal" way is to use a Musicbrainz Tagger, open these files there and work with the interface to attach the correct metadata.
The suggested (gui) tool is Musicbrain Picard
I also want to state that the Perl module is using the now deprecated Web Service Version 1 of MusicBrainz.
That Web Service has a couple of problems because it was made for another database scheme than the one used now at MusicBrainz.
However, the current Web Service Version 2 has only a python library available: python-musicbrainzngs.
You can still work with the Perl module, but if you run into "weird" problems, this might be the reason.
This is how the Web Service works in general (and how it should apply directly for the Perl module as a wrapper for this web service):
Your search gives this:
http://musicbrainz.org/ws/1/track/?artist=%22Ryan%20Adams%22&title=%22when%20the%20stars%20go%20blue%22
There you get a list of recordings of this track. These recodings occur on multiple releases (ReleaseList).
You can disregard many of these, as they are of the type "compilation". You probably want the "album" releases.
You probably ask yourself why there are multiple album releases with the same name in the list.
This is because a "release" on MusicBrainz is a combination of a release-event and a couple of mediums.
You might have an US release and a german deluxe edition and so on.
All of these releases are in one "release group".
You probably want the name of this "release group", which mostly is also the name of every release in this group.
You might want to read a bit on how the MusicBrainz Database is structured.
This is only the basic use case of course.
You might run into misspellings in artist/title, multiple or missing album release groups and other things.
However, altogether it should work and you can just drop the "problem" cases in a special directory and work with them in Picard.
Picard also has other means of identifying files per "musical analysis" (PUIDs, Acoustids)
EDIT:
my #tracklist = $response->track_list();
foreach my $track ( #tracklist ) {
print $track->title(), " - ", $track->artist()->name(), "\n";
my #releaselist = $track->release_list();
foreach my $release ( #releaselist ) {
print " ", $release->title(), " - ", $release->type();
}
}
Should work in general, but it doesn't. It gives you all tracks of the response, but somehow it can't extract releases from release_list(). Possibly because the schema changed or because the perl module is broken.
Check out our perl modules for accessing the Cover Art Archive:
http://metacpan.org/pod/Net::CoverArtArchive
More info on our archive is here, including specs:
http://coverartarchive.org/
Good luck!

Erroring in my Perl script coming from CAM::PDF::Annot module. Don't know why

I believe this may be a bug in the module I am using, or I am just completely overlooking something.
My code is this:
#!/usr/bin/perl
use strict;
use warnings;
use CAM::PDF;
use CAM::PDF::Annot;
sub main()
{
my $pdf = CAM::PDF::Annot->new( 'b.pdf' );
my $otherDoc = CAM::PDF::Annot->new( 'b_an.pdf' );
my $page = 1;
my %refs;
my #list = #{$pdf->getAnnotations($page)};
for my $annotRef (#list){
$otherDoc->appendAnnotation( $page, $pdf, $annotRef, \%refs);
}
$otherDoc->output('pdf_merged.pdf');
}
exit main;
This code was taken almost directly from the synopsis found on the module's CPAN page: http://metacpan.org/pod/CAM::PDF::Annot
The problem comes when I run the script using TWO pdf's with annotations. Using two pdf's without annotations runs. Using one pdf with annotations, and one pdf without annotations, runs. Only when both pdf's have annotations does it error.
The error is: "Can't use string ("46") as an ARRAY ref while "strict refs" in use at /usr/opt/perl5/lib/site_perl/5.10.1/CAM/PDF/Annot.pm line 195"
Line 195 of Annot.pm is:
push #{$annots->{value}}, $pupRef;
Annot.pm is inside the CAM::PDF::Annot module.
Any guidance in fixing this would be greatly appreciated!
P.S. In the error, "string ("x")", x is always a number, and seems to change depending on the pdf and the annotations within the pdf.
And I will try to add any other information that you need to help figure this out!
Whenever I have a problem with a CPAN module, I go to its webpage to try and assess its quality and see if any bugs have already been reported.
http://search.cpan.org/~donatoaz/CAM-PDF-Annot-0.06 shows the following suspicious results:
CPAN Testers PASS (2) FAIL (168) NA (49)
It is surprising that you were able to install the module. No one has reported bugs, but there is clearly a major problem with the code. It seems the author is either unaware of the tester reports (which have been sent to his CPAN email address for more than a year), or has stopped maintaining it.
You could submit a bug report, so at least others will be aware of your issue.
I realize this does not answer your question of how to fix the problem, but even if you do identify a fix, the author may not apply it (in which case, someone could start the process of becoming a co-maintaner).

Opening Web Site

I'm kind of new at Perl. A friend of mine asks me to write him a program that could search specific ad on his favourite boat for sale Web Site. It's a very convenient little program that will allow a user to search multiple Web Sites for specific ads.
Here is how it works. I load up the Web Page into a temporary file and search for matching ad and return the result. It works fine most of the time but I noticed that some site won't load up and I don’t know why.
Here is the script that loads the pages and stores it a temp file:
use LWP::UserAgent;
use HTTP::Response;
use URI::Heuristic;
unless (defined ($content = get ($URL) )) { print "could not get $URL <br>"; }
open (DATABASE, ">$web_page_file");
print DATABASE "$content";
close (DATABASE);
#
I've been successfully run it on many sites and it works fine. But recently, 2 sites won't load up. It's :
http://www.babord.ca
http://www.sailboatlistings.com
I have 2 Questions:
A) Can you tell me what is wrong with my script with these two sites?
B) More important, is there a diagnostic tool that can tell me what the problems are (for future problem site)?
The example you posted doesn't work at all for me, and you don't say exactly what isn't working with the two examples you give so it's tough to debug your sample. The below works and I think is a cleaner way of getting what you're looking for:
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $URL = 'http://www.yourboatsite.com';
my $mech = WWW::Mechanize->new(); #Autocheck defaults to ON to check for success.
$mech->get($URL); # Use :content_file option to auto-write to a file.
print $mech->content();
You also probably want to tag your entry as perl rather than mod-perl since it's not a mod_perl problem.

Can't post with Perl's Net::Blogger

I'm trying to automatically post to blogger using Perl's Net::Blogger but it keeps returning false and not posting. The main portion of my code looks like this:
use Net::Blogger;
my $blogger = Net::Blogger->new({
debug => 1,
appkey => '0123456789ABCDEF', # doesn't matter?
blogid => $blogid,
username => $username,
password => $password,
});
my $result = $blogger->newPost({
postbody => \'<p>This is text</p><hr/><p><strong>Whee!</strong></p>',
publish => 1,
});
use Data::Dumper;
print Dumper($result);
Sure enough, $result is 0 and in checking the blog, nothing has been posted. The error I'm getting when I enable debugging is:
Element '' can't be allowed in valid XML message.
Died. at /Library/Perl/5.10.1/SOAP/Lite.pm line 1410.
What am I doing wrong?
If you can suggest an alternative to Net::Blogger, that would be fine.
Update: if I don't enable debugging, it hangs for quite a while when trying to post.
I can understand your frustration, I don't like it when I try to use a CPAN module which is seductively named (i.e. looks like a good scratch for the itch) but is ultimately not useful. However, Net::Blogger had its last update in 2006 so I think it would be incredible if it still worked as originally intended, given that blogger has been evolving over the years.
Per daxim's rec, I made a quick attempt to install Atompub on OS X via CPAN.pm, but failed due to a hard dependency on Perl::Critic, which won't install. I figure I know how to fix this but I'll need a better reason than this to go to the effort.
I saw this note in the Net::Blogger perldoc which if nothing else provides a hint on another module to try, for anyone who didn't feel like beating Atompub into submission:
The Atom API
In January 2004, Blogger announced
their support for the Atom API.
As of this writing (version 0.87) this
package does not support the Atom API.
If you need to do things Atom-ish,
your best bet is to use the XML::Atom
package.
Alternative as you requested: after all the different blogging APIs, a standard in the form of RFC 5023 emerged.
Atompub works fine.
I worked a bit with Net::Logger today and managed to publish an entry into Blogger, the problem is that only the body can be set (no Atom supported as virtualsue told).
Please take a look at my Perl Posting to Blogger blues entry for some help.