Rev 280 |
Rev 313 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#!/usr/bin/perl -w
use strict
;
# Thu, 13 Nov 2008 21:06:23 +0100
# Maciej 'agaran' Pijanka <agaran@pld-linux.org>
# for OpenARM SBC Project
# license: gpl v3
use Getopt
::Long qw//;
# ITS UNFINISHED
# idea/todo
# -v for verbose (muiltiple for more)
# -q for quiet or -s for silent?
#
# some file with definitions of required fields
# if not present (default) then hardcoded data will
# be used
#
# split elements by types so defaults/required-fields
# different for different types could be applied
#
# --verbose
# --file "pathtoschematic"
# --list "id,description,partid,manufacturer,ordercode,quanity,price,total"
# --list "id,description,partid,footprint,refdes,sheet"
# --configfile "pathtoconfigfile:
# --search partid "LD1117S12TR"
#
# inventory.conf
# path-to-directory-of-external-component-information
# path-to-directory-of-schematics
# match information-source to "information.txt"
# match description to "Description:"
# match manufacturer to "Manufacturer:"
# match ordercode to "Order Code:"
# calculate total per schematics
# calculate total sum of all schematics
# layout asci
# spaces one
# merge schematics information
# seperate schematics information
#
# first stage is build list of all data found (no caching concept yet)
# then find all sch and make bom? or find already done boms?
sub dbg_printf
($$@) {
my ($lvl, $format, @args) = @_;
return if ($lvl >= 3) ;
printf STDERR $format, @args;
}
sub parse_ifile
($) {
my ($filepath) = @_;
open(IN
, $filepath) or return 1;
while (not eof IN
) {
my $line = <IN>;
chomp $line;
if ($line =~ /^[A-Z][a-z]+[ ]*:[ ]+.*$/) {
my ($name,$value) = split (/[ ]*:[ ]+/, $line);
if ($name =~ /^price$/i) {
} elsif ($name =~ /^manufacturer$/i) {
} elsif ($name =~ /^description$/i) {
} elsif ($name =~ /^datasheet$/i) {
} elsif ($name =~ /^supplier$/i) {
} elsif ($name =~ /^$/i) {
} else {
dbg_printf
(1, "UNHANDLED IDATA %s = %s\n", $name, $value);
}
} else {
dbg_printf
(3, "REST %s\n", $line);
}
}
close(IN
);
}
sub build_ifile_list
($);
sub build_ifile_list
($) {
my ($dir) = @_;
if ( -d
$dir) {
opendir(DIR
, $dir) or return 1;
foreach my $e (readdir(DIR
)) {
my $fe = $dir .'/'. $e;
if ( -f
$fe) {
# Whoo file we have
if ($e =~ /\.[pP][dD][fF]$/) {
# its an pdf file if filename is correct
dbg_printf
(3, "PDF %s\n", $fe);
} elsif ($e eq 'information.txt') {
# we found an information.txt file
dbg_printf
(2, "IFILE %s\n", $fe);
parse_ifile
($fe);
} else {
printf STDERR "FILE %s\n", $fe;
}
} elsif (-d
$fe) { # now its dir...
if ($e eq '.svn') { # if entry name is equal to svn
next; # go to next entry in foreach loop
}
next if ($e eq '.' or $e eq '..'); # skip to next if dir entry is . or ..
dbg_printf
(3, "DIR %s\n", $fe);
# so we are in dir and not unwanted one
build_ifile_list
($fe);
# so scan deeper
} else {
# symlink or other myserius beast
}
}
closedir(DIR
);
}
}
build_ifile_list
('.');