📄 archive.pl
字号:
#!/usr/local/bin/perl
#
# DESCRIPTION: This file is to be combined within the pcb_dir.pl script. This script will have
# several features. First, it will remove all unwanted files that Allegro and PADS
# leaves behind in the job directories. Second, it will compress the directory
# contents and FTP that compressed file over to the Archive PC. Third, it will
# modify the CD label Word document and print out the labels automatically.
#
# CREATED BY : Jason E. Smith
# CREATED ON : March 12, 2001
#
# MODIFIED : April 4, 2001
# Created a new pattern matching scheme to derive the job number, customer name,
# board name and revision level from the directory. This appears to be more accurate.
#
# BEGIN CREATION OF MAIN WINDOW
use Net::FTP;
use Tk;
my $mw = MainWindow->new;
$mw->title("PCB Job Utility");
$os = $^O;
# GET DATE, TIME, JOB DIRECTORY
if ($os eq "MSWin32" || $os eq "Windows_NT" || $os =~ /win/i) {
$date = `"date /t"`;
$time = `"time /t"`;
chomp($date, $time);
$tmp = `chdir`;
chomp $tmp;
$dir = $tmp;
$dir =~ s/.+\\//g;
print "Directory name = $dir\n"; ## FOR TESTING PURPOSES
$job = $dir;
$job =~ s/^(\d+).+_.+_r.+$/$1/;
print "Job number = $job\n"; ## FOR TESTING PURPOSES
$cust = $dir;
$cust =~ s/^\d+(.+)_.+_r.+$/$1/;
print "Customer name = $cust\n"; ## FOR TESTING PURPOSES
$brd = $dir;
$brd =~ s/^\d+.+_(.+)_r.+$/$1/;
print "Board name = $brd\n"; ## FOR TESTING PURPOSES
$rev = $dir;
$rev =~ s/^\d+.+_.+_r(.+)$/$1/;
print "Revision level = $rev\n"; ## FOR TESTING PURPOSES
} else {
chomp($date = `date`);
}
# CREATE MENU BAR
$menubar = $mw->Frame()->pack(-side => 'top', -anchor => 'n', -expand => 1, -fill => 'x');
# CREATE FILE MENU
$file_menu = $menubar->Menubutton(-text => "File", -tearoff => 0, -menuitems =>
[["command" => "Exit", -command => sub { $mw->destroy(); } ]])->pack(-side => 'left');
# CREATE HELP MENU
$help_menu = $menubar->Menubutton(-text => "Help", -tearoff => 0, -menuitems =>
[["command" => "Contact", -command => sub { }],
["command" => "Contents", -command => sub { }],
"-",
["command" => "About", -command => sub { }]])->pack(-side => 'right');
# CREATE RADIO BUTTONS
$rb1 = $mw->Radiobutton(-text => "Clean and archive job directory.", -value => "archive", -variable => \$choice)->pack(-side => 'top', -anchor => 'w');
$rb2 = $mw->Radiobutton(-text => "Create CD Labels.", -value => "labels", -variable => \$choice)->pack(-side => 'top', -anchor => 'w');
# CREATE BUTTON
$btn = $mw->Button(-text => "Okay", -command => sub {
if ($choice eq "archive") {
archive();
} elsif ($choice eq "labels") {
labels();
} elsif (!defined $choice) {
error();
}
})->pack(-side => 'bottom', -anchor => 's');
# CLEAN, ARCHIVE AND FTP TO ARCHIVE
sub archive {
@trash = ("*.jrl", "*.log*", "*.tag*", "*.sav*", "*.form*", "*.did*", "*.*1", "*.*2", "*.*3", "*.*4", "*.*5");
foreach $trash (@trash) {
`del /s $trash`;
}
`zip -gqrD $dir.zip *`;
$ftp = Net::FTP->new("archive", Debug => 0);
$ftp->login("archive", 'archive');
$ftp->cwd("$ENV{USERNAME}");
$ftp->binary();
$ftp->put("$dir.zip");
$ftp->quit;
}
# CREATE AND PRINT CD LABELS
sub labels {
$msw = $mw->Toplevel;
$msw->resizable(0, 0);
$msw->raise($mw);
$msw->title("CD Labels Printout");
$frm1 = $msw->Frame()->pack(-side => 'top', -anchor => 'n', -expand => 1, -fill => 'x');
$frm1->Label(-text => "Please input the following information.")->pack(-side => 'top', -anchor => 'w');
$frm1->Label(-text => "Part Number: ")->pack(-side => 'left', -anchor => 'w');
$frm1->Entry(-text => "", -textvariable => \$part)->pack(-side => 'left', -anchor => 'w');
$frm2 = $msw->Frame()->pack(-side => 'top', -anchor => 'n', -expand => 1, -fill => 'x');
$frm2->Radiobutton(-text => "Allegro", -value => "Cadence Allegro v13.6", -variable => \$soft)->pack(-side => 'left', -anchor => 'e');
$frm2->Radiobutton(-text => "PowerPCB", -value => "PADS-PowerPCB v3.5.1", -variable => \$soft)->pack(-side => 'right', -anchor => 'w');
$frm3 = $msw->Frame()->pack(-side => 'top', -anchor => 'n', -expand => 1, -fill => 'x');
$btn1 = $frm3->Button(-text => "Okay", -command => sub {
msword();
$msw->withdraw;
})->pack(-side => 'left');
$btn2 = $frm3->Button(-text => "Cancel", -command => sub { $msw->withdraw; })->pack(-side => 'right');
}
sub msword {
$spine = "Part #$part Job #$job $date";
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Word';
my $word = Win32::OLE->new('Word.Application');
$word->{'Visible'} = 1;
$word->Documents->Open("$ENV{WINDIR}\\cd_labels.doc") || die("Unable to open document ", Win32::OLE->LastError());;
$word->ActiveDocument->Shapes("Text Box 85")->Select();
$word->Selection->TypeText("$spine");
$word->ActiveDocument->Shapes("Text Box 86")->Select();
$word->Selection->TypeText("$cust");
$word->ActiveDocument->Shapes("Text Box 87")->Select();
$word->Selection->TypeText("$brd");
$word->ActiveDocument->Shapes("Text Box 88")->Select();
$word->Selection->TypeText("Part #$part");
$word->ActiveDocument->Shapes("Text Box 89")->Select();
$word->Selection->TypeText("Rev #$rev");
$word->ActiveDocument->Shapes("Text Box 90")->Select();
$word->Selection->TypeText("Job #$job");
$word->ActiveDocument->Shapes("Text Box 91")->Select();
$word->Selection->TypeText("$date");
$word->ActiveDocument->Shapes("Text Box 93")->Select();
$word->Selection->TypeText("$soft");
$word->ActiveDocument->Shapes("Text Box 94")->Select();
$word->Selection->TypeText("$spine");
$word->ActiveDocument->Shapes("Text Box 95")->Select();
$word->Selection->TypeText("$cust");
$word->ActiveDocument->Shapes("Text Box 96")->Select();
$word->Selection->TypeText("$brd");
$word->ActiveDocument->Shapes("Text Box 97")->Select();
$word->Selection->TypeText("Part #$part");
$word->ActiveDocument->Shapes("Text Box 98")->Select();
$word->Selection->TypeText("Rev #$rev");
$word->ActiveDocument->Shapes("Text Box 99")->Select();
$word->Selection->TypeText("Job #$job");
$word->ActiveDocument->Shapes("Text Box 100")->Select();
$word->Selection->TypeText("$date");
$word->ActiveDocument->Shapes("Text Box 102")->Select();
$word->Selection->TypeText("$soft");
}
MainLoop;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -