To solve this problem, we first need to define the decision variables and the objective function. Let's denote the number of stuffed donuts as \(D\) and the number of pastries as \(P\). The objective is to maximize profit, which can be represented by the equation \(2D + 4P\), given that each donut contributes $2 to profit and each pastry contributes $4.

The constraints are based on the availability of machines:
1. Baking machine constraint: Each stuffed donut takes 2 minutes, and each pastry takes 5 minutes. The total time used cannot exceed 10000 minutes. This gives us \(2D + 5P \leq 10000\).
2. Stuffing machine constraint: Each stuffed donut takes 3 minutes, and each pastry takes 2 minutes. The total time used cannot exceed 7000 minutes. This gives us \(3D + 2P \leq 7000\).

Additionally, we have non-negativity constraints since the number of donuts and pastries cannot be negative: \(D \geq 0\) and \(P \geq 0\).

Now, let's express this problem in Gurobi code using Python:

```python
from gurobipy import *

# Create a model
m = Model("Bakery_Optimization")

# Define decision variables
D = m.addVar(lb=0, vtype=GRB.INTEGER, name="Donuts")
P = m.addVar(lb=0, vtype=GRB.INTEGER, name="Pastries")

# Objective function: Maximize profit
m.setObjective(2*D + 4*P, GRB.MAXIMIZE)

# Constraints
m.addConstr(2*D + 5*P <= 10000, "Baking_Machine_Constraint")
m.addConstr(3*D + 2*P <= 7000, "Stuffing_Machine_Constraint")

# Optimize model
m.optimize()

# Print results
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Donuts: {D.x}")
    print(f"Pastries: {P.x}")
    print(f"Max Profit: {m.objVal}")
else:
    print("No optimal solution found")
```