angrox / spacewalk-api-scripts

Addon script for spacewalk to sync RHN packages to a local spacewalk server
GNU General Public License v3.0
67 stars 32 forks source link

spacewalk-remove-old-packages.py - UnboundLocalError: local variable 'ret' referenced before assignment #28

Closed storm49152 closed 7 years ago

storm49152 commented 7 years ago

Running the script I get:

Getting all packages without channel
Packages to remove: 11484
Deleting packages from spacewalk (if packages could not be removed they are maybe in another channel too)
Deleting package docker-engine-1.11.2-1.el7.centos (ID: 179245)
  - Could not delete package from Spacewalk
Traceback (most recent call last):
  File "/root/spacewalk-scripts/spacewalk-remove-old-packages.py", line 218, in <module>
    main()
  File "/root/spacewalk-scripts/spacewalk-remove-old-packages.py", line 210, in main
    if ret != 1:
UnboundLocalError: local variable 'ret' referenced before assignment

It happens when an "except" is triggered; "ret" is then apparently not assigned, but the "if ret != 1:" line is still executed. Since I guess it only makes sense to execute the "if" line when "ret" is assigned, I moved it into the "try" block.

spacewalk-remove-old-packages.py.diff.txt

angrox commented 7 years ago

Can you make a pull request with your diff?

storm49152 commented 7 years ago

I just created a pull request.

angrox commented 7 years ago

Thanks for the bugfix! :-)