ids-update.pl: add Generated header with a date
authorMichal Minar <miminar@redhat.com>
Fri, 23 Oct 2015 12:05:37 +0000 (14:05 +0200)
committerMichal Minar <miminar@redhat.com>
Fri, 23 Oct 2015 12:11:14 +0000 (14:11 +0200)
Also extend generated file's header for date of source file.

Related: rhbz#1266217

Signed-off-by: Michal Minar <miminar@redhat.com>
ids-update.pl

index 86d414a6ffecf835ed63280684d26bca4d896b67..ca580385f5a6dc0ba31e0c647d05e41974a6a6c1 100644 (file)
@@ -2,18 +2,31 @@
 
 use strict;
 use warnings;
+use Date::Format;
 
 sub usb_vendor {
         my $vendor;
+        my $source_date;
 
         open(IN, "<", "usb.ids");
         open(OUT, ">", "20-usb-vendor-model.hwdb");
         print(OUT "# This file is part of systemd.\n" .
+                  "#\n" .
+                  "# Generated:     " . time2str("%Y-%m-%d\n", time) .
                   "#\n" .
                   "# Data imported from: http://www.linux-usb.org/usb.ids\n");
 
         while (my $line = <IN>) {
                 $line =~ s/\s+$//;
+                if (not defined $source_date) {
+                    $line =~ m/^#\s*Date:\s*(.+)$/;
+                    if (defined $1) {
+                            $source_date = $1;
+                            print(OUT "#\n# Source date: $1\n");
+                            next;
+                    }
+                }
+
                 $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
                 if (defined $1) {
                         $vendor = uc $1;
@@ -42,16 +55,28 @@ sub usb_classes {
         my $class;
         my $subclass;
         my $protocol;
+        my $source_date;
 
         open(IN, "<", "usb.ids");
         open(OUT, ">", "20-usb-classes.hwdb");
         print(OUT "# This file is part of systemd.\n" .
+                  "#\n" .
+                  "# Generated:     " . time2str("%Y-%m-%d\n", time) .
                   "#\n" .
                   "# Data imported from: http://www.linux-usb.org/usb.ids\n");
 
         while (my $line = <IN>) {
                 $line =~ s/\s+$//;
 
+                if (not defined $source_date) {
+                    $line =~ m/^#\s*Date:\s*(.+)$/;
+                    if (defined $1) {
+                            $source_date = $1;
+                            print(OUT "#\n# Source date: $1\n");
+                            next;
+                    }
+                }
+
                 $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
                 if (defined $1) {
                         $class = uc $1;
@@ -108,17 +133,29 @@ sub pci_vendor {
         my $vendor;
         my $device;
         my $device_text;
+        my $source_date;
 
         open(IN, "<", "pci.ids");
         open(OUT, ">", "20-pci-vendor-model.hwdb");
         print(OUT "# This file is part of systemd.\n" .
+                  "#\n" .
+                  "# Generated:     " . time2str("%Y-%m-%d\n", time) .
                   "#\n" .
                   "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
 
         while (my $line = <IN>) {
                 $line =~ s/\s+$//;
-                $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
 
+                if (not defined $source_date) {
+                    $line =~ m/^#\s*Date:\s*(.+)$/;
+                    if (defined $1) {
+                            $source_date = $1;
+                            print(OUT "#\n# Source date: $1\n");
+                            next;
+                    }
+                }
+
+                $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
                 if (defined $1) {
                         $vendor = uc $1;
                         my $text = $2;
@@ -159,16 +196,28 @@ sub pci_classes {
         my $class;
         my $subclass;
         my $interface;
+        my $source_date;
 
         open(IN, "<", "pci.ids");
         open(OUT, ">", "20-pci-classes.hwdb");
         print(OUT "# This file is part of systemd.\n" .
+                  "#\n" .
+                  "# Generated:     " . time2str("%Y-%m-%d\n", time) .
                   "#\n" .
                   "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
 
         while (my $line = <IN>) {
                 $line =~ s/\s+$//;
 
+                if (not defined $source_date) {
+                    $line =~ m/^#\s*Date:\s*(.+)$/;
+                    if (defined $1) {
+                            $source_date = $1;
+                            print(OUT "#\n# Source date: $1\n");
+                            next;
+                    }
+                }
+
                 $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
                 if (defined $1) {
                         $class = uc $1;
@@ -216,13 +265,15 @@ sub sdio_vendor {
         open(IN, "<", "sdio.ids");
         open(OUT, ">", "20-sdio-vendor-model.hwdb");
         print(OUT "# This file is part of systemd.\n" .
+                  "#\n" .
+                  "# Generated:     " . time2str("%Y-%m-%d\n", time) .
                   "#\n" .
                   "# Data imported from: hwdb/sdio.ids\n");
 
         while (my $line = <IN>) {
                 $line =~ s/\s+$//;
-                $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
 
+                $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
                 if (defined $1) {
                         $vendor = uc $1;
                         my $text = $2;
@@ -255,6 +306,8 @@ sub sdio_classes {
         open(IN, "<", "sdio.ids");
         open(OUT, ">", "20-sdio-classes.hwdb");
         print(OUT "# This file is part of systemd.\n" .
+                  "#\n" .
+                  "# Generated:     " . time2str("%Y-%m-%d\n", time) .
                   "#\n" .
                   "# Data imported from: hwdb/sdio.ids\n");
 
@@ -279,9 +332,12 @@ sub sdio_classes {
 sub oui {
         my $iab_prefix;
         my %iab_prefixes = ();
+        my $source_date;
 
         open(OUT, ">", "20-OUI.hwdb");
         print(OUT "# This file is part of systemd.\n" .
+                  "#\n" .
+                  "# Generated:     " . time2str("%Y-%m-%d\n", time) .
                   "#\n" .
                   "# Data imported from:\n" .
                   "#   http://standards.ieee.org/develop/regauth/oui/oui.txt\n" .
@@ -290,6 +346,16 @@ sub oui {
         open(IN, "<", "iab.txt");
         while (my $line = <IN>) {
                 $line =~ s/^ +//;
+
+                if (not defined $source_date) {
+                    $line =~ m/^\s*Generated:\s+(.+)$/;
+                    if (defined $1) {
+                            $source_date = $1;
+                            print(OUT "#\n# Source date: $1\n");
+                            next;
+                    }
+                }
+
                 $line =~ s/\s+$//;
                 $line =~ m/^([0-9A-F]{2})-([0-9A-F]{2})-([0-9A-F]{2})\s*\(hex\)\s*.+$/;
                 if (defined $1) {