Subversion Repositories DevTools

Rev

Rev 4640 | Rev 4666 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4640 Rev 4641
Line 30... Line 30...
30
#                   available to be packaged.
30
#                   available to be packaged.
31
#
31
#
32
#                 Summary of directives available to the user-script:
32
#                 Summary of directives available to the user-script:
33
#                       AddInitScript           - Add an init script
33
#                       AddInitScript           - Add an init script
34
#                       CatFile                 - Append to a file
34
#                       CatFile                 - Append to a file
-
 
35
#                       ConvertFile             - Convert file(s) to Unix or Dos Text
35
#                       CopyDir                 - Copy directory tree
36
#                       CopyDir                 - Copy directory tree
36
#                       CopyFile                - Copy a file
37
#                       CopyFile                - Copy a file
37
#                       CopyBinFile             - Copy an executable file
38
#                       CopyBinFile             - Copy an executable file
38
#                       CopyLibFile             - Copy a library file
39
#                       CopyLibFile             - Copy a library file
39
#                       CreateDir               - Create a directory
40
#                       CreateDir               - Create a directory
Line 41... Line 42...
41
#                       DebianControlFile       - Specify control and script files
42
#                       DebianControlFile       - Specify control and script files
42
#                       DebianDepends           - Add Depends entry to control file
43
#                       DebianDepends           - Add Depends entry to control file
43
#                       EchoFile                - Place text into a file
44
#                       EchoFile                - Place text into a file
44
#                       MakeSymLink             - Create a symbolic link
45
#                       MakeSymLink             - Create a symbolic link
45
#                       PackageDescription      - Specify the package description
46
#                       PackageDescription      - Specify the package description
-
 
47
#                       ReplaceTags             - Replace Tags on target file
46
#                       SetFilePerms            - Set file permissions
48
#                       SetFilePerms            - Set file permissions
47
#                       SetVerbose              - Control progress display
49
#                       SetVerbose              - Control progress display
48
#                       IsProduct               - Flow control
50
#                       IsProduct               - Flow control
49
#                       IsPlatform              - Flow control
51
#                       IsPlatform              - Flow control
50
#                       IsTarget                - Flow control
52
#                       IsTarget                - Flow control
51
#                       IsVariant               - Flow control
53
#                       IsVariant               - Flow control
52
#
54
#
53
#                 Thoughts for expansion:
55
#                 Thoughts for expansion:
54
#                       ConvertFile             - Option to convert file(s) to Unix Text
-
 
55
#                       ReplaceTags             - Replace Tags on target file
-
 
56
#                       SrcDir                  - Extend path for resolving local files
56
#                       SrcDir                  - Extend path for resolving local files
57
#
57
#
58
#                   Less used:
58
#                   Less used:
59
#                        ExpandLinkFiles        - Expand .LINK files
59
#                        ExpandLinkFiles        - Expand .LINK files
60
#
60
#
61
#                   Internal Use:
61
#                   Internal Use:
62
#                        FindFiles              - Find a file
62
#                        FindFiles              - Find a file
63
#                        ResolveFile            - Resolve a 'local' source file
63
#                        ResolveFile            - Resolve a 'local' source file
-
 
64
#                        chmodItem              - Set file or directory permissions
64
#                        
65
#                        
65
#......................................................................#
66
#......................................................................#
66
 
67
 
67
require 5.006_001;
68
require 5.006_001;
68
use strict;
69
use strict;
Line 1227... Line 1228...
1227
        } elsif ( m~^--Unix~) {
1228
        } elsif ( m~^--Unix~) {
1228
            $lineEnding = "\n";
1229
            $lineEnding = "\n";
1229
            $unixSet = 1;
1230
            $unixSet = 1;
1230
 
1231
 
1231
        } elsif ( m~^--~) {
1232
        } elsif ( m~^--~) {
1232
            Error ("ConvertFile: Unknown option: $_");
1233
            Error ("ConvertFiles: Unknown option: $_");
1233
 
1234
 
1234
        } else {
1235
        } else {
1235
            push @uargs, $_;
1236
            push @uargs, $_;
1236
        }
1237
        }
1237
    }
1238
    }
Line 1277... Line 1278...
1277
    {
1278
    {
1278
 
1279
 
1279
        # this is our file that we want to clean.
1280
        # this is our file that we want to clean.
1280
        my ($ifileLoc) = "$topDir/$file";
1281
        my ($ifileLoc) = "$topDir/$file";
1281
        my ($tfileLoc) = "$topDir/$file\.tmp";
1282
        my ($tfileLoc) = "$topDir/$file\.tmp";
1282
        Verbose("ConvertFile: $file");
1283
        Verbose("ConvertFiles: $file");
1283
 
1284
 
1284
        # we will check to see if the file exists.
1285
        # we will check to see if the file exists.
1285
        #
1286
        #
1286
        my $ifile;
1287
        my $ifile;
1287
        my $tfile;
1288
        my $tfile;
Line 1321... Line 1322...
1321
        }
1322
        }
1322
    }
1323
    }
1323
 
1324
 
1324
    return 1;
1325
    return 1;
1325
}
1326
}
-
 
1327
 
-
 
1328
#----------------------------------------------------------------------------
-
 
1329
# Function        : ReplaceTags
-
 
1330
#
-
 
1331
# Description     : This sub-routine is used to replace Tags in one or more files
-
 
1332
#
-
 
1333
# Inputs          : outPath                 - Output directory
-
 
1334
#                   flist                   - List of files in that directory
-
 
1335
#                   or
-
 
1336
#                   SearchOptions           - Search options to find files
-
 
1337
#                                           --Recurse
-
 
1338
#                                           --NoRecurse
-
 
1339
#                                           --FilterIn=xxx
-
 
1340
#                                           --FilterInRe=xxx
-
 
1341
#                                           --FilterOut=xxx
-
 
1342
#                                           --FilterOutRe=xxx
-
 
1343
#                   Common options
-
 
1344
#                                           --Tag=Tag,Replace
-
 
1345
#                                           
-
 
1346
#
-
 
1347
# Returns         : 1
-
 
1348
#
-
 
1349
sub ReplaceTags
-
 
1350
{
-
 
1351
    my @uargs;
-
 
1352
    my $search =  JatsLocateFiles->new( '--NoRecurse' );
-
 
1353
    my @tagsList;
-
 
1354
    my $tagSep = ',';
-
 
1355
    my @tagOrder;
-
 
1356
    my %tagData;
-
 
1357
 
-
 
1358
    #
-
 
1359
    #   Process user arguments extracting options
-
 
1360
    #
-
 
1361
    foreach  ( @_ )
-
 
1362
    {
-
 
1363
        if ( m~^--Recurse~ ) {
-
 
1364
            $search->recurse(1);
-
 
1365
 
-
 
1366
        } elsif ( m~^--NoRecurse~) {
-
 
1367
            $search->recurse(0);
-
 
1368
 
-
 
1369
        } elsif ( /^--FilterOut=(.*)/ ) {
-
 
1370
            $search->filter_out($1);
-
 
1371
 
-
 
1372
        } elsif ( /^--FilterOutRe=(.*)/ ) {
-
 
1373
            $search->filter_out_re($1);
-
 
1374
 
-
 
1375
        } elsif ( /^--FilterIn=(.*)/ ) {
-
 
1376
            $search->filter_in($1);
-
 
1377
 
-
 
1378
        } elsif ( /^--FilterInRe=(.*)/ ) {
-
 
1379
            $search->filter_in_re($1);
-
 
1380
 
-
 
1381
        } elsif ( m~^--Tag=(.*)~) {
-
 
1382
            push @tagsList, $1;
-
 
1383
 
-
 
1384
        } elsif ( m~^--~) {
-
 
1385
            Error ("ReplaceTags: Unknown option: $_");
-
 
1386
 
-
 
1387
        } else {
-
 
1388
            push @uargs, $_;
-
 
1389
        }
-
 
1390
    }
-
 
1391
 
-
 
1392
    #
-
 
1393
    #   Process non-option arguments
-
 
1394
    #       - Base dir
-
 
1395
    #       - List of files
-
 
1396
    #
-
 
1397
    my ($outPath, @flist) = @uargs;
-
 
1398
    Error ("ReplaceTags: Target Dir must be specified" ) unless ( $outPath );
-
 
1399
 
-
 
1400
    #
-
 
1401
    #   Sanity Tests
-
 
1402
    #
-
 
1403
    Error ("ReplaceTags: No tags specified" ) unless ( @tagsList );
-
 
1404
 
-
 
1405
    #
-
 
1406
    # Convert output path to physical path
-
 
1407
    #
-
 
1408
    my $topDir = catdir($DebianWorkDir, $outPath);
-
 
1409
    Verbose("ReplaceTags: topDir: $topDir");
-
 
1410
    Error ("ReplaceTags: Path does not exist", $topDir) unless ( -e $topDir );
-
 
1411
    Error ("ReplaceTags: Path is not a directory", $topDir) unless ( -d $topDir );
-
 
1412
 
-
 
1413
    #
-
 
1414
    #   Convert Tags into pairs for latter use
-
 
1415
    #
-
 
1416
    my $sep = quotemeta ($tagSep );
-
 
1417
    foreach my $tag ( @tagsList )
-
 
1418
    {
-
 
1419
        my ($tname,$tvalue) = split ( $sep, $tag );
-
 
1420
        Error ("No tag value in: $tag" ) unless ( defined $tvalue );
-
 
1421
        Error ("Duplicate Tag: $tname" ) if ( exists $tagData{$tname} );
-
 
1422
        Verbose ("Tag: $tname :: $tvalue");
-
 
1423
        push @tagOrder, $tname;
-
 
1424
        $tagData{$tname} = $tvalue;
-
 
1425
    }
-
 
1426
 
-
 
1427
    #
-
 
1428
    #   Need to determine if we are searching or simply using a file list
-
 
1429
    #   There are two forms of the functions. If any of the search options have
-
 
1430
    #   been used then we assume that we are searchine
-
 
1431
    #
-
 
1432
    if ( $search->has_filter() )
-
 
1433
    {
-
 
1434
        Error ("ReplaceTags: Cannot mix search options with named files") if ( @flist );
-
 
1435
        @flist = $search->search($topDir);
-
 
1436
    }
-
 
1437
    Error ("ReplaceTags: No files specified") unless ( @flist );
-
 
1438
 
-
 
1439
    #
-
 
1440
    #   Process all named files
-
 
1441
    #
-
 
1442
    foreach my $file ( @flist )
-
 
1443
    {
-
 
1444
 
-
 
1445
        # this is our file that we want to clean.
-
 
1446
        my ($ifileLoc) = "$topDir/$file";
-
 
1447
        my ($tfileLoc) = "$topDir/$file\.tmp";
-
 
1448
        Verbose("ReplaceTags: $file");
-
 
1449
 
-
 
1450
        # we will check to see if the file exists.
-
 
1451
        #
-
 
1452
        my $ifile;
-
 
1453
        my $tfile;
-
 
1454
        if ( -f "$ifileLoc" )
-
 
1455
        {
-
 
1456
            open ($ifile, "< $ifileLoc" ) or
-
 
1457
                Error("Failed to open file [$ifileLoc] : $!");
-
 
1458
 
-
 
1459
            open ($tfile, "> $tfileLoc" ) or
-
 
1460
                Error("Failed to open file [$tfileLoc] : $!");
-
 
1461
 
-
 
1462
            while ( <$ifile> ) 
-
 
1463
            {
-
 
1464
                s~[\n\r]+$~~;               # Chomp
-
 
1465
 
-
 
1466
                #
-
 
1467
                #   Perform tag replacement
-
 
1468
                #
-
 
1469
                foreach my $tag ( @tagOrder )
-
 
1470
                {
-
 
1471
                    my $value = $tagData{$tag};
-
 
1472
                    if ( s~$tag~$value~g )
-
 
1473
                    {
-
 
1474
                        Verbose2("Replaced: $tag with $value");
-
 
1475
                    }
-
 
1476
                }
-
 
1477
 
-
 
1478
                print $tfile "$_\n";
-
 
1479
            }
-
 
1480
        }
-
 
1481
        else
-
 
1482
        {
-
 
1483
            Error("ReplaceTags [$ifileLoc] does not exist.");
-
 
1484
        }
-
 
1485
 
-
 
1486
        close $ifile;
-
 
1487
        close $tfile;
-
 
1488
 
-
 
1489
 
-
 
1490
        # lets replace our original file with the new one
-
 
1491
        #
-
 
1492
        if(File::Copy::move("$tfileLoc", "$ifileLoc"))
-
 
1493
        {
-
 
1494
            Verbose2("ReplaceTags: Renamed [$tfileLoc] to [$ifileLoc] ...");
-
 
1495
        }
-
 
1496
        else
-
 
1497
        {
-
 
1498
            Error("ReplaceTags: Failed to rename file [$tfileLoc] to [$ifileLoc]: $!");
-
 
1499
        }
-
 
1500
    }
-
 
1501
 
-
 
1502
    return 1;
-
 
1503
}
1326
 
1504
 
1327
#-------------------------------------------------------------------------------
1505
#-------------------------------------------------------------------------------
1328
# Function        : SetFilePerms
1506
# Function        : SetFilePerms
1329
#
1507
#
1330
# Description     : Set file permissions on one or more files or directories
1508
# Description     : Set file permissions on one or more files or directories