Debbugs::Common -- Common routines for all of Debbugs
use Debbugs::Common qw(:url :html);
This module is a replacement for the general parts of errorlib.pl. subroutines in errorlib.pl will be gradually phased out and replaced with equivalent (or better) functionality here.
The following functions are exported by the :util
tag
my $file = getbugcomponent($bug_number,$extension,$location)
Returns the path to the bug file in location $location
, bug number $bugnumber
and extension $extension
getbuglocation($bug_number,$extension)
Returns the the location in which a particular bug exists; valid locations returned currently are archive, db-h, or db. If the bug does not exist, returns undef.
getlocationpath($location)
Returns the path to a specific location
get_hashname
Returns the hash of the bug which is the location within the archive
buglog($bugnum);
Returns the path to the logfile corresponding to the bug.
Returns undef if the bug does not exist.
bug_status($bugnum)
Returns the path to the summary file corresponding to the bug.
Returns undef if the bug does not exist.
appendfile($file,'data','to','append');
Opens a file for appending and writes data to it.
ovewritefile($file,'data','to','append');
Opens file.new, writes data to it, then moves file.new to file.
my $address = getparsedaddrs($address); my @address = getparsedaddrs($address);
Returns the output from Mail::Address->parse, or the cached output if this address has been parsed before. In SCALAR context returns the first address parsed.
my $maintainer = getmaintainers()->{debbugs}
Returns a hashref of package => maintainer pairs.
my @packages = @{getmaintainers_reverse->{'don@debian.org'}||[]};
Returns a hashref of maintainer => [qw(list of packages)] pairs.
my @s = package_maintainer(source => [qw(foo bar baz)], binary => [qw(bleh blah)], );
my $pseudopkgdesc = getpseudodesc(...);
Returns the entry for a pseudo package from the $config{pseudo_desc_file}. In cases where pseudo_desc_file is not defined, returns an empty arrayref.
This function can be used to see if a particular package is a pseudopackage or not.
sort_versions('1.0-2','1.1-2');
Sorts versions using AptPkg::Versions::compare if it is available, or Debbugs::Versions::Dpkg::vercmp if it isn't.
my $english = secs_to_english($seconds); my ($days,$english) = secs_to_english($seconds);
XXX This should probably be changed to use Date::Calc
These functions are exported with the :lock tag
filelock($lockfile); filelock($lockfile,$locks);
FLOCKs the passed file. Use unfilelock to unlock it.
Can be passed an optional $locks hashref, which is used to track which files are locked (and how many times they have been locked) to allow for cooperative locking.
unfilelock() unfilelock($locks);
Unlocks the file most recently locked.
Note that it is not currently possible to unlock a specific file locked with filelock.
lockpid('/path/to/pidfile');
Creates a pidfile '/path/to/pidfile' if one doesn't exist or if the pid in the file does not respond to kill 0.
Returns 1 on success, false on failure; dies on unusual errors.
checkpid('/path/to/pidfile');
Checks a pid file and determines if the process listed in the pidfile is still running. Returns the pid if it is, 0 if it isn't running, and undef if the pidfile doesn't exist or cannot be read.
These functions are exported with the :quit tag.
quit()
Exits the program by calling die.
Usage of quit is deprecated; just call die instead.
These functions are exported with the :misc tag
LIST = make_list(@_);
Turns a scalar or an arrayref into a list; expands a list of arrayrefs into a list.
That is, make_list([qw(a b c)]); returns qw(a b c); make_list([qw(a b)],[qw(c d)] returns qw(a b c d);
print english_join(list => \@list); print english_join(\@list);
Joins list properly to make an english phrase.
In cases where list
is empty, returns ''; when there is only one element, returns that element.
my $handle = globify_scalar(\$foo);
if $foo isn't already a glob or a globref, turn it into one using IO::Scalar. Gives a new handle to /dev/null if $foo isn't defined.
Will carp if given a scalar which isn't a scalarref or a glob (or globref), and return /dev/null. May return undef if IO::Scalar or IO::File fails. (Check $!)
print "Something failed with: ".cleanup_eval_fail($@);
Does various bits of cleanup on the failure message from an eval (or any other die message)
Takes at most two options; the first is the actual failure message (usually $@ and defaults to $@), the second is the debug level (defaults to $DEBUG).
If debug is non-zero, the code at which the failure occured is output.
hash_slice(%hash,qw(key1 key2 key3))
For each key, returns matching values and keys of the hash if they exist
These functions are exported with the :utf8 tag
%newdata = encode_utf8_structure(%newdata);
Takes a complex data structure and encodes any strings with is_utf8 set into their constituent octets.