aboutsummaryrefslogtreecommitdiffstats
path: root/RepSys/rpm.py
blob: d448c5f414d4e9957f719a8a18864154ba8b6e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/python
from RepSys.util import execcmd

class SRPM:
    def __init__(self, filename):
        self.filename = filename
        self._getinfo()

    def _getinfo(self):
        cmdstr = "rpm -qp --qf '%%{name} %%{epoch} %%{release} %%{version}' %s"
        status, output = execcmd(cmdstr % self.filename)
        self.name, self.epoch, self.release, self.version = output.split()
        if self.epoch == "(none)":
            self.epoch = None

    def unpack(self, topdir):
        execcmd("rpm -i --define '_topdir %s' %s" % (topdir, self.filename))

# vim:et:ts=4:sw=4
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
package fsedit;

use diagnostics;
use strict;

use common qw(:common);
use partition_table qw(:types);
use partition_table_raw;
use devices;
use log;

1;

my @suggestions = (
  { mntpoint => "/boot",    minsize =>  10 << 11, size =>  16 << 11, type => 0x83 }, 
  { mntpoint => "/",        minsize =>  50 << 11, size => 100 << 11, type => 0x83 }, 
  { mntpoint => "swap",     minsize =>  30 << 11, size =>  60 << 11, type => 0x82 },
  { mntpoint => "/usr",     minsize => 200 << 11, size => 500 << 11, type => 0x83 }, 
  { mntpoint => "/home",    minsize =>  50 << 11, size => 200 << 11, type => 0x83 }, 
  { mntpoint => "/var",     minsize => 200 << 11, size => 250 << 11, type => 0x83 }, 
  { mntpoint => "/tmp",     minsize =>  50 << 11, size => 100 << 11, type => 0x83 }, 
  { mntpoint => "/mnt/iso", minsize => 700 << 11, size => 800 << 11, type => 0x83 }, 
);


1;

sub hds($$) {
    my ($drives, $flags) = @_;
    my @hds;
    my $rc;

    foreach (@$drives) {
	my $file = devices::make($_->{device});

	my $hd = partition_table_raw::get_geometry($file) or die "An error occurred while getting the geometry of block device $file: $!";
	$hd->{file} = $file;
	$hd->{prefix} = $hd->{device} = $_->{device};
	# for RAID arrays of format c0d0p1 
	$hd->{prefix} .= "p" if $hd->{prefix} =~ m,(rd|ida)/,;

	eval { $rc = partition_table::read($hd, $flags->{clearall}) }; 
	if ($@) {
	    $@ =~ /bad magic number/ or die;
	    partition_table_raw::zero_MBR($hd) if $flags->{eraseBadPartitions};
	}
	$rc ? push @hds, $hd : log::l("An error occurred reading the partition table for the block device $_->{device}");
    }
    [ @hds ];
}

sub get_fstab(@) {
    map { partition_table::get_normal_parts($_) } @_;
}

sub suggest_part($$$;$) {
    my ($hd, $part, $hds, $suggestions) = @_;
    $suggestions ||= \@suggestions;
    foreach (@$suggestions) { $_->{minsize} ||= $_->{size} }

    my $has_swap;
    my @mntpoints = map { $has_swap ||= isSwap($_); $_->{mntpoint} } get_fstab(@$hds);
    my %mntpoints; @mntpoints{@mntpoints} = undef;

    my ($best, $second) = 
      grep { $part->{size} >= $_->{minsize} }
      grep { !exists $mntpoints{$_->{mntpoint}} || isSwap($_) && !$has_swap }
	@$suggestions or return;

    $best = $second if 
      $best->{mntpoint} eq '/boot' && 
      $part->{start} + $best->{minsize} > 1024 * partition_table::cylinder_size($hd); # if the empty slot is beyond the 1024th cylinder, no use having /boot

    defined $best or return; # sorry no suggestion :(

    $part->{mntpoint} = $best->{mntpoint};
    $part->{type} = $best->{type};
    $part->{size} = min($part->{size}, $best->{size});
    1;
}


#sub partitionDrives {