Subversion Repositories OpenARM Single-board Computer

Rev

Rev 280 | Rev 293 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
280 agaran 1
#!/usr/bin/perl -w
2
use strict;
3
# Thu, 13 Nov 2008 21:06:23 +0100
4
# Maciej 'agaran' Pijanka <agaran@pld-linux.org>
5
# for OpenARM SBC Project
6
# license: gpl v3
7
 
8
use Getopt::Long qw//;
9
 
10
# ITS UNFINISHED
11
 
12
# idea/todo
13
# -v for verbose (muiltiple for more)
14
# -q for quiet or -s for silent?
15
#
16
# some file with definitions of required fields
17
# if not present (default) then hardcoded data will
18
# be used
19
#
20
# split elements by types so defaults/required-fields
21
# different for different types could be applied
22
#
281 jelle 23
# --verbose
24
# --file "pathtoschematic"
25
# --list "id,description,partid,manufacturer,ordercode,quanity,price,total"
26
# --list "id,description,partid,footprint,refdes,sheet"
27
# --configfile "pathtoconfigfile:
28
# --search partid "LD1117S12TR"
29
#
30
# inventory.conf
31
# path-to-directory-of-external-component-information
32
# path-to-directory-of-schematics
33
# match information-source to "information.txt"
34
# match description to "Description:"
35
# match manufacturer to "Manufacturer:"
36
# match ordercode to "Order Code:"
37
# calculate total per schematics
38
# calculate total sum of all schematics
39
# layout asci
40
# spaces one
41
# merge schematics information
42
# seperate schematics information
43
#
280 agaran 44
# first stage is build list of all data found (no caching concept yet)
45
# then find all sch and make bom? or find already done boms?
46
 
47
sub dbg_printf($$@) {
281 jelle 48
    my ($lvl, $format, @args) = @_;
280 agaran 49
 
281 jelle 50
    return if ($lvl >= 3) ;
280 agaran 51
 
281 jelle 52
    printf STDERR $format, @args;
280 agaran 53
}
54
 
55
sub parse_ifile($) {
281 jelle 56
    my ($filepath) = @_;
280 agaran 57
 
281 jelle 58
    open(IN, $filepath) or return 1;
280 agaran 59
 
281 jelle 60
    while (not eof IN) {
61
        my $line = <IN>;
280 agaran 62
 
281 jelle 63
        chomp $line;
280 agaran 64
 
281 jelle 65
        if ($line =~ /^[A-Z][a-z]+[     ]*:[    ]+.*$/) {
66
            my ($name,$value) = split (/[   ]*:[    ]+/, $line);
67
            if ($name =~ /^price$/i) {
68
            } elsif ($name =~ /^manufacturer$/i) {
69
            } elsif ($name =~ /^description$/i) {
70
            } elsif ($name =~ /^datasheet$/i) {
71
            } elsif ($name =~ /^supplier$/i) {
72
            } elsif ($name =~ /^$/i) {
73
            } else {
74
                dbg_printf(1, "UNHANDLED IDATA %s = %s\n", $name, $value);
75
            }
76
        } else {
77
            dbg_printf(3, "REST %s\n", $line);
78
        }
79
    }
80
    close(IN);
280 agaran 81
 
82
}
83
 
84
sub build_ifile_list($);
85
sub build_ifile_list($) {
281 jelle 86
    my ($dir) = @_;
280 agaran 87
 
88
 
281 jelle 89
    if ( -d $dir) {
90
        opendir(DIR, $dir) or return 1;
91
        foreach my $e (readdir(DIR)) {
92
            my $fe = $dir .'/'. $e;
93
            if ( -f $fe) {
94
                # Whoo file we have
95
                if ($e =~ /\.[pP][dD][fF]$/) {
96
                    # its an pdf file if filename is correct
97
                    dbg_printf(3, "PDF %s\n", $fe);
98
                } elsif ($e eq 'information.txt') {
99
                    # we found an information.txt file
100
                    dbg_printf(2, "IFILE %s\n", $fe);
101
                    parse_ifile($fe);
102
                } else {
103
                    printf STDERR "FILE %s\n", $fe;
104
                }
105
            } elsif (-d $fe) { # now its dir...
106
                if ($e eq '.svn') { # if entry name is equal to svn
107
                    next; # go to next entry in foreach loop
108
                }
109
                next if ($e eq '.' or $e eq '..'); # skip to next if dir entry is . or ..
110
 
111
                dbg_printf(3, "DIR %s\n", $fe);
112
                # so we are in dir and not unwanted one
113
                build_ifile_list($fe);
114
                # so scan deeper
115
            } else {
116
                # symlink or other myserius beast
117
            }
118
        }
119
        closedir(DIR);
120
    }
280 agaran 121
}
122
 
123
build_ifile_list('.');
124