releasing/cbrtools/perl/Symbian/DistributionPolicy/Reader.pm
author Bob Rosenberg <bob.rosenberg@nokia.com>
Tue, 03 Aug 2010 12:14:54 +0100
changeset 634 f7179968fc36
parent 602 3145852acc89
permissions -rw-r--r--
Add verbatim functionality to filtering so it can perform chassis builds. Add ProductsDefinition file for defining exports.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
package Symbian::DistributionPolicy::Reader;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use Symbian::DistributionPolicy;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
our $cache = {}; # Persistent (private) cache
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
sub new {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
    return bless {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
# public.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
sub ReadPolicyFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
    my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
    my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
    my $dir  = -d $path ? $path : dirname($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
    # look in cache first, retrieve if not already defined
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
    return $cache->{$dir} ||= $self->readfile($dir.'\\DISTRIBUTION.POLICY');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
# private.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
sub readfile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
    my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
    my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
    my $hasCategory;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
    my $policy = Symbian::DistributionPolicy->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
    # default policy applies when the file does not exist
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
    return $policy if !-e $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
    # attempt to open the policy file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
    open(POLICY, $file) or die "Couldn't open $file: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
    # read policy data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
    while (<POLICY>) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
        s/(?<!\\)#.*$//;  # ignore comments
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
        s/^\s+|\s+$//g;   # trim whitespace
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
        next unless /\S/; # skip blank line
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
        # parse line
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
        if (/^authori[sz]ed\s+(.+?)(?:\s+until\s+(.+?))?$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
            # licensee specific authorisation
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
            if (!$policy->SetAuthorizedUntil($1, $2)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
                warn "Invalid Authorized directive in $file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
            }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
        } elsif (/^category\s+([a-z])$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
            # ipr category
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
            if (!$policy->SetCategory($1)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
                warn "Invalid Category directive in $file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
            }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
            $hasCategory = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
        } elsif (/^description\s+(.*)$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
            # free text description
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
            $policy->SetDescription($1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
        } elsif (/^expires\s+(.*)$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
            # best before date
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
            if (!$policy->SetExpires($1)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
                warn "Invalid Expires directive in $file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
            }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
        } elsif (/^export\s+(un)?restricted$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
            # exportable/embargoed?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
            $policy->SetExportRestricted(!defined($1));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
        } elsif (/^osd:\s*(.+?)$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
            # parse osd info
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
            $self->handle_osd($1, $policy);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
    close(POLICY);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
    if (!$hasCategory) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
        warn "Warning: \'$file\' does not contain an IPR category\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
    return $policy;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
sub handle_osd {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
    my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
    local $_ = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
    my $policy = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
    # SGL.PPS246.201DistributionPolicyFileContents.doc
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
    if (/^(common|optional)\s+(symbian|replaceable)\s+(.+)$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
        # set common/optional
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
        if (lc($1) eq 'common') {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
            $policy->SetCommon(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
        } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
            $policy->SetOptional(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
        # set symbian/replaceable
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
        if (lc($2) eq 'symbian') {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
            $policy->SetSymbian(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
        } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
            $policy->SetReplaceable(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
    } elsif (/^(?:reference\/test)\s+(.+)$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
        # set test
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
        $policy->SetTest(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
    } elsif (/^(?:test\/reference)\s+(.+)$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
        # synonym for reference/test
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
        $policy->SetTest(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
    } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
        warn "Invalid OSD directive: '$_' (see SGL.PPS246.201)\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
=pod
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
Symbian::DistributionPolicy::Reader - Caching DISTRIBUTION.POLICY file reader.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
 use Symbian::DistributionPolicy::Reader;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
 my $dpr = Symbian::DistributionPolicy::Reader->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
 my $policy = $dpr->ReadPolicyFile($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
This module parses and caches policy data from DISTRIBUTION.POLICY files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
=head1 METHODS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
=head2 new()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
Creates the reader object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
=head2 ReadPolicyFile($path)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
Read the DISTRIBUTION.POLICY file in $path (which can be e.g. a source file, a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
directory or the DISTRIBUTION.POLICY file itself) and return a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
Symbian::DistributionPolicy object containing the policy data. The policy is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
cached to prevent unnecessary re-reading of .POLICY files in subsequent calls.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
=head1 SEE ALSO
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
L<Symbian::DistributionPolicy> to find out what you can do with your $policy
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
 Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
=cut