Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exported package count #12

Merged
merged 1 commit into from
Oct 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions sat_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,25 @@ def read_pickle(name):
return export_times


def get_product(org_id, cp_id):
"""
Find and return the label of the given product ID
"""
prod_list = helpers.get_p_json(
helpers.KATELLO_API + "/products/", \
json.dumps(
{
"organization_id": org_id,
"per_page": '1000',
}
))

for prod in prod_list['results']:
if prod['cp_id'] == cp_id:
prodlabel = prod['label']
return prodlabel


def main():
"""
Main Routine
Expand Down Expand Up @@ -500,7 +519,6 @@ def main():
export_type = 'full'
else:
# TODO: Re-populate export_times dictionary so each repo has 'since' date
since = True
since_export = str(since)

# We have our timestamp so we can kick of an incremental export
Expand Down Expand Up @@ -625,7 +643,21 @@ def main():
# Check if the export completed OK. If not we exit the script.
tinfo = helpers.get_task_status(export_id)
if tinfo['state'] != 'running' and tinfo['result'] == 'success':
msg = "Repository Export OK"
# Count the number of exported packages
# First resolve the product label - this forms part of the export path
product = get_product(org_id, repo_result['product']['cp_id'])
# Now we can build the export path itself
basepath = helpers.EXPORTDIR + "/" + org_name + "-" + product + "-" + repo_result['label']
if export_type == 'incr':
basepath = basepath + "-incremental"
exportpath = basepath + "/" + repo_result['relative_path']
msg = "Export path = " + exportpath
helpers.log_msg(msg, 'DEBUG')

os.chdir(exportpath)
numrpms = len([f for f in os.walk(".").next()[2] if f[ -4: ] == ".rpm"])

msg = "Repository Export OK (" + str(numrpms) + " new packages)"
helpers.log_msg(msg, 'INFO')
print helpers.GREEN + msg + helpers.ENDC

Expand All @@ -634,6 +666,7 @@ def main():

# Add the repo to the successfully exported list
exported_repos.append(repo_result['label'])

else:
msg = "Export FAILED"
helpers.log_msg(msg, 'ERROR')
Expand Down Expand Up @@ -671,7 +704,7 @@ def main():
# And we're done!
print helpers.GREEN + "Export complete.\n" + helpers.ENDC
print 'Please transfer the contents of ' + helpers.EXPORTDIR + \
'to your disconnected Satellite system content import location.\n' \
' to your disconnected Satellite system content import location.\n' \
'Once transferred, please run ' + helpers.BOLD + ' sat_import' \
+ helpers.ENDC + ' to extract it.'

Expand Down