Guest User

Untitled

a guest
Aug 13th, 2020
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None
  1. def uploadArtifact(
  2.         api_dest,
  3.         repository,
  4.         username,
  5.         password,
  6.         groupId,
  7.         artifactId,
  8.         version,
  9.         path,
  10.         assets
  11.         ):
  12.  
  13.     params = (
  14.         ('repository', repository),
  15.     )
  16.  
  17.     files = {
  18.       'maven2.groupId': (None, groupId),
  19.       'maven2.artifactId': (None, artifactId),
  20.       'maven2.version': (None, version),
  21.       'maven2.generate-pom': (None, 'false')
  22.     }
  23.  
  24.     i = 1
  25.  
  26.     while i <= len(assets):
  27.         asset_key = "maven2.asset" + str(i)
  28.         asset_extension_key = "maven2.asset" + str(i) + ".extension"
  29.         asset_value = str(path + assets[i - 1])
  30.         asset_extension_value = assets[i - 1].split('.')[-1]
  31.         files.update({asset_key: (asset_value, open(asset_value, 'rb'))})
  32.         files.update({asset_extension_key: (None, asset_extension_value)})
  33.         i += 1
  34.  
  35.     # print(files)
  36.  
  37.     response = requests.post(
  38.                  api_dest + "/v1/components",
  39.                  params=params,
  40.                  files=files,
  41.                  auth=requests.auth.HTTPBasicAuth(username, password)
RAW Paste Data Copied