{"action":"created","issue":{"url":"https://api.github.com/repos/sheagcraig/Spruce/issues/6","labels_url":"https://api.github.com/repos/sheagcraig/Spruce/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/sheagcraig/Spruce/issues/6/comments","events_url":"https://api.github.com/repos/sheagcraig/Spruce/issues/6/events","html_url":"https://github.com/sheagcraig/Spruce/issues/6","id":101679639,"number":6,"title":"Getting packages not listed in my jss","user":{"login":"charliwest","id":7933076,"avatar_url":"https://avatars.githubusercontent.com/u/7933076?v=3","gravatar_id":"","url":"https://api.github.com/users/charliwest","html_url":"https://github.com/charliwest","followers_url":"https://api.github.com/users/charliwest/followers","following_url":"https://api.github.com/users/charliwest/following{/other_user}","gists_url":"https://api.github.com/users/charliwest/gists{/gist_id}","starred_url":"https://api.github.com/users/charliwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charliwest/subscriptions","organizations_url":"https://api.github.com/users/charliwest/orgs","repos_url":"https://api.github.com/users/charliwest/repos","events_url":"https://api.github.com/users/charliwest/events{/privacy}","received_events_url":"https://api.github.com/users/charliwest/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-08-18T15:12:10Z","updated_at":"2015-09-03T15:48:52Z","closed_at":null,"body":"When I run this I get packages in the output that aren't listed in my jss, then if I try and run it to remove them all I get errors.\r\nAre there perhaps packages I'm not seeing for some reason?\r\n\r\nThe error is\r\n./Spruce.py --remove output.txt\r\nTraceback (most recent call last):\r\n  File \"./Spruce.py\", line 367, in <module>\r\n    main()\r\n  File \"./Spruce.py\", line 363, in main\r\n    remove(j, removal_set)\r\n  File \"./Spruce.py\", line 220, in remove\r\n    j.distribution_points.delete(item)\r\n  File \"/Library/Python/2.7/site-packages/python_jss-1.2.0-py2.7.egg/jss/distribution_points.py\", line 246, in delete\r\n    repo.delete(filename)\r\n  File \"/Library/Python/2.7/site-packages/python_jss-1.2.0-py2.7.egg/jss/distribution_points.py\", line 870, in delete\r\n    self.connection['jss'].Package(filename).delete()\r\n  File \"/Library/Python/2.7/site-packages/python_jss-1.2.0-py2.7.egg/jss/jss.py\", line 421, in Package\r\n    return self.factory.get_object(Package, data)\r\n  File \"/Library/Python/2.7/site-packages/python_jss-1.2.0-py2.7.egg/jss/jss.py\", line 524, in get_object\r\n    xmldata = self.jss.get(url)\r\n  File \"/Library/Python/2.7/site-packages/python_jss-1.2.0-py2.7.egg/jss/jss.py\", line 231, in get\r\n    self._error_handler(JSSGetError, response)\r\n  File \"/Library/Python/2.7/site-packages/python_jss-1.2.0-py2.7.egg/jss/jss.py\", line 185, in _error_handler\r\n    raise exception\r\njss.exceptions.JSSGetError: Response Code: 404\tResponse: Not Found. The server has not found anything matching the request URI"},"comment":{"url":"https://api.github.com/repos/sheagcraig/Spruce/issues/comments/137491069","html_url":"https://github.com/sheagcraig/Spruce/issues/6#issuecomment-137491069","issue_url":"https://api.github.com/repos/sheagcraig/Spruce/issues/6","id":137491069,"user":{"login":"sheagcraig","id":3568072,"avatar_url":"https://avatars.githubusercontent.com/u/3568072?v=3","gravatar_id":"","url":"https://api.github.com/users/sheagcraig","html_url":"https://github.com/sheagcraig","followers_url":"https://api.github.com/users/sheagcraig/followers","following_url":"https://api.github.com/users/sheagcraig/following{/other_user}","gists_url":"https://api.github.com/users/sheagcraig/gists{/gist_id}","starred_url":"https://api.github.com/users/sheagcraig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sheagcraig/subscriptions","organizations_url":"https://api.github.com/users/sheagcraig/orgs","repos_url":"https://api.github.com/users/sheagcraig/repos","events_url":"https://api.github.com/users/sheagcraig/events{/privacy}","received_events_url":"https://api.github.com/users/sheagcraig/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T15:48:52Z","updated_at":"2015-09-03T15:48:52Z","body":"Aha! This all makes sense now.\r\n\r\nAgain, I don't have a test server, so the removal algorithm is my best guess.\r\n\r\nHere's what happens:\r\n1. Get the API object for the thing you want to delete (in this case, a package)\r\n    a. If that package doesn't exist as an object in the DB, just go to the next one.\r\n    b. If it does exist, delete the DB side of things.\r\n2. If you have DP's configured, and it's an object type that has a file (packages and sometimes scripts), try to delete them.\r\n    a. For file share DP's, mount the shares and do a delete.\r\n    b. For JDS DP's, there is no (public-api anyway) way to delete packages; but you can just delete the db object. So it tries to do that. Except you delete the db object in 1.b, so it throws a JSSGetError.\r\n\r\nAND I didn't catch JSSGetError's; just OSError (which is the exception you get when you try to delete a file that doesn't exist).\r\n\r\nSo, if you want to try adding this:\r\n```\r\n             except jss.JSSGetError:\r\n                 # Tried to delete the db object again because user has a\r\n                 # JDS or CDP. Just silently continue.\r\n                 pass\r\n```\r\n to line 1880 (so it looks like this):\r\n```\r\n         if item.tag in needs_file_removal and file_type_removals:\r\n             try:\r\n                 jss_connection.distribution_points.delete(item.text)\r\n                 print \"%s file %s deleted.\" % (item.tag, obj.name)\r\n             except OSError as error:\r\n                 print (\"Unable to delete %s: %s with error: %s\" %\r\n                        (item.tag, item.text, error.message))\r\n             except jss.JSSGetError:\r\n                 # Tried to delete the db object again because user has a\r\n                 # JDS or CDP. Just silently continue.\r\n                 pass\r\n```\r\n\r\nand then run again, let me know how it goes. If it works, I'll rush that out as the first 2.0 update."}}