First, the landlord is not required by law to replace the carpet or repaint unless they make the place uninhabitable.
Your real issue is with being charged for damages to the carpet or repainting.
In CA, you should only be charged for the useful life of the damaged carpet. It does not matter how long you lived there. It is the age of the carpet and it's life expectancy that determines how much a tenant can be charged. See #2 below.
Repainting is similar, however, it dies depend on how long you have resided in the rental. After 2 years, a tenant should not be charged at all unless there is damage to the walls as opposed to the paint. See #3 below.
The sections below are directly from California's Department of Consumer Affairs Landlord/Tenant Booklet.
http://www.dca.ca.gov/publications/landl
They are not the law, however, they are consistent with the law. They are practical guides/suggested approaches to security deposit deductions.
That said, California is considered a very tenant friendly state when it comes to housing issues.
2. Carpets and drapes - %26quot;useful life%26quot; rule
Normal wear and tear to carpets, drapes and other furnishings cannot be charged against a tenant's security deposit. Normal wear and tear includes simple wearing down of carpet and drapes because of normal use or aging, and includes moderate dirt or spotting. In contrast, large rips or indelible stains justify a deduction from the tenant's security deposit for repairing the carpet or drapes, or replacing them if that is reasonably necessary.
One common method of calculating the deduction for replacement prorates the total cost of replacement so that the tenant pays only for the remaining useful life of the item that the tenant has damaged or destroyed. For example, suppose a tenant has damaged beyond repair an eight-year-old carpet that had a life expectancy of ten years, and that a replacement carpet of similar quality would cost $1,000. The landlord could properly charge only $200 for the two years' worth of life (use) that would have remained if the tenant had not damaged the carpet.
3. Repainting walls
One approach for determining the amount that the landlord can deduct from the tenant's security deposit for repainting, when repainting is necessary, is based on the length of the tenant's stay in the rental unit. This approach assumes that interior paint has a two-year life. (Some landlords assume that interior paint has a life of three years or more.)
Length of stay - Deduction
Less than 6 months - full cost
6 months to 1 year - two-thirds of cost
1 year to 2 years - one-third of cost
2 or more years - no deduction
Using this approach, if the tenant lived in the rental unit for two years or more, the tenant could not be charged for any repainting costs, no matter how dirty the walls were.