We compute the supersymmetric partition function of N = 1 supersymmetric gauge theories with an R-symmetry on M-4 congruent to M-g,M-p x S-1, a principal elliptic fiber bundle of degree p over a genus-g Riemann surface, Sigma(g). Equivalently, we compute the generalized supersymmetric index I-Mg,(p), with the supersymmetric three-manifold M-g,M-p as the spatial slice. The ordinary N = 1 supersymmetric index on the round three-sphere is recovered as a special case. We approach this computation from the point of view of a topological A-model for the abelianized gauge fields on the base Sigma(g). This A-model - or A-twisted two-dimensional N = (2; 2) gauge theory encodes all the information about the generalized indices, which are viewed as expectations values of some canonically-defined surface defects wrapped on T-2 inside Sigma(g) x T-2. Being de fined by compactification on the torus, the A model also enjoys natural modular properties, governed by the four-dimensional 't Hooft anomalies. As an application of our results, we provide new tests of Seiberg duality. We also present a new evaluation formula for the three-sphere index as a sum over two-dimensional vacua.