Rev 280 | Rev 293 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 280 | Rev 281 | ||
---|---|---|---|
Line 18... | Line 18... | ||
18 | # be used
|
18 | # be used
|
19 | #
|
19 | #
|
20 | # split elements by types so defaults/required-fields
|
20 | # split elements by types so defaults/required-fields
|
21 | # different for different types could be applied
|
21 | # different for different types could be applied
|
22 | #
|
22 | #
|
- | 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"
|
|
23 | 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 | #
|
|
24 | # first stage is build list of all data found (no caching concept yet)
|
44 | # first stage is build list of all data found (no caching concept yet)
|
25 | # then find all sch and make bom? or find already done boms?
|
45 | # then find all sch and make bom? or find already done boms?
|
26 | 46 | ||
27 | - | ||
28 | sub dbg_printf($$@) { |
47 | sub dbg_printf($$@) { |
29 | my ($lvl, $format, @args) = @_; |
48 | my ($lvl, $format, @args) = @_; |
30 | 49 | ||
31 | return if ($lvl >= 3) ; |
50 | return if ($lvl >= 3) ; |
32 | 51 | ||
33 | printf STDERR $format, @args; |
52 | printf STDERR $format, @args; |
34 | }
|
53 | }
|
35 | 54 | ||
36 | sub parse_ifile($) { |
55 | sub parse_ifile($) { |
37 | my ($filepath) = @_; |
56 | my ($filepath) = @_; |
38 | 57 | ||
39 | open(IN, $filepath) or return 1; |
58 | open(IN, $filepath) or return 1; |
40 | 59 | ||
41 | while (not eof IN) { |
60 | while (not eof IN) { |
42 | my $line = <IN>; |
61 | my $line = <IN>; |
43 | 62 | ||
44 | chomp $line; |
63 | chomp $line; |
45 | 64 | ||
46 | if ($line =~ /^[A-Z][a-z]+[ ]*:[ ]+.*$/) { |
65 | if ($line =~ /^[A-Z][a-z]+[ ]*:[ ]+.*$/) { |
47 | my ($name,$value) = split (/[ ]*:[ ]+/, $line); |
66 | my ($name,$value) = split (/[ ]*:[ ]+/, $line); |
48 | if ($name =~ /^price$/i) { |
67 | if ($name =~ /^price$/i) { |
49 | } elsif ($name =~ /^manufacturer$/i) { |
68 | } elsif ($name =~ /^manufacturer$/i) { |
50 | } elsif ($name =~ /^description$/i) { |
69 | } elsif ($name =~ /^description$/i) { |
51 | } elsif ($name =~ /^datasheet$/i) { |
70 | } elsif ($name =~ /^datasheet$/i) { |
52 | } elsif ($name =~ /^supplier$/i) { |
71 | } elsif ($name =~ /^supplier$/i) { |
53 | } elsif ($name =~ /^$/i) { |
72 | } elsif ($name =~ /^$/i) { |
54 | } else { |
73 | } else { |
55 | dbg_printf(1, "UNHANDLED IDATA %s = %s\n", $name, $value); |
74 | dbg_printf(1, "UNHANDLED IDATA %s = %s\n", $name, $value); |
56 | }
|
75 | }
|
57 | } else { |
76 | } else { |
58 | dbg_printf(3, "REST %s\n", $line); |
77 | dbg_printf(3, "REST %s\n", $line); |
59 | }
|
78 | }
|
60 | }
|
79 | }
|
61 | close(IN); |
80 | close(IN); |
62 | 81 | ||
63 | }
|
82 | }
|
64 | 83 | ||
65 | sub build_ifile_list($); |
84 | sub build_ifile_list($); |
66 | sub build_ifile_list($) { |
85 | sub build_ifile_list($) { |
67 | my ($dir) = @_; |
86 | my ($dir) = @_; |
68 | 87 | ||
69 | 88 | ||
70 | if ( -d $dir) { |
89 | if ( -d $dir) { |
71 | opendir(DIR, $dir) or return 1; |
90 | opendir(DIR, $dir) or return 1; |
72 | foreach my $e (readdir(DIR)) { |
91 | foreach my $e (readdir(DIR)) { |
73 | my $fe = $dir .'/'. $e; |
92 | my $fe = $dir .'/'. $e; |
74 | if ( -f $fe) { |
93 | if ( -f $fe) { |
75 | # Whoo file we have
|
94 | # Whoo file we have
|
76 | if ($e =~ /\.[pP][dD][fF]$/) { |
95 | if ($e =~ /\.[pP][dD][fF]$/) { |
77 | # its an pdf file if filename is correct
|
96 | # its an pdf file if filename is correct
|
78 | dbg_printf(3, "PDF %s\n", $fe); |
97 | dbg_printf(3, "PDF %s\n", $fe); |
79 | } elsif ($e eq 'information.txt') { |
98 | } elsif ($e eq 'information.txt') { |
80 | # we found an information.txt file
|
99 | # we found an information.txt file
|
81 | dbg_printf(2, "IFILE %s\n", $fe); |
100 | dbg_printf(2, "IFILE %s\n", $fe); |
82 | parse_ifile($fe); |
101 | parse_ifile($fe); |
83 | } else { |
102 | } else { |
84 | printf STDERR "FILE %s\n", $fe; |
103 | printf STDERR "FILE %s\n", $fe; |
85 | }
|
104 | }
|
86 | } elsif (-d $fe) { # now its dir... |
105 | } elsif (-d $fe) { # now its dir... |
87 | if ($e eq '.svn') { # if entry name is equal to svn |
106 | if ($e eq '.svn') { # if entry name is equal to svn |
88 | next; # go to next entry in foreach loop |
107 | next; # go to next entry in foreach loop |
89 | }
|
108 | }
|
90 | next if ($e eq '.' or $e eq '..'); # skip to next if dir entry is . or .. |
109 | next if ($e eq '.' or $e eq '..'); # skip to next if dir entry is . or .. |
91 | 110 | ||
92 | dbg_printf(3, "DIR %s\n", $fe); |
111 | dbg_printf(3, "DIR %s\n", $fe); |
93 | # so we are in dir and not unwanted one
|
112 | # so we are in dir and not unwanted one
|
94 | build_ifile_list($fe); |
113 | build_ifile_list($fe); |
95 | # so scan deeper
|
114 | # so scan deeper
|
96 | } else { |
115 | } else { |
97 | # symlink or other myserius beast
|
116 | # symlink or other myserius beast
|
98 | }
|
117 | }
|
99 | }
|
118 | }
|
100 | closedir(DIR); |
119 | closedir(DIR); |
101 | }
|
120 | }
|
102 | }
|
121 | }
|
103 | 122 | ||
104 | build_ifile_list('.'); |
123 | build_ifile_list('.'); |
105 | 124 |