Created
September 2, 2020 23:07
-
-
Save michael-adam-sheehan/1ec5332b4e0c0bee1580282f604f7ed3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getChangeSetStatus(self): | |
hourlyTimestamp = datetime.fromtimestamp(datetime.utcnow().timestamp() - (3600 * 6)) | |
dtFormat = '%Y-%m-%dT%H:%M:%S-00:00%z' | |
query = f"SELECT EventType, LogDate, LogFileFieldNames, LogFile, Interval FROM EventLogFile WHERE EventType='ChangeSetOperation' AND Interval='Hourly' AND LogDate >= {hourlyTimestamp.strftime(dtFormat)}" | |
url = f"{self._auth['instanceUrl']}/services/data/v{apiVersion}/query/?q={quote_plus(query)}" | |
eventTypeLogResult = self._client.request('GET', url).json() | |
for result in eventTypeLogResult['records']: | |
url = f"{self._auth['instanceUrl']}{result['LogFile']}" | |
logfileResult = self._client.request('GET', url).text | |
df = pd.read_csv(StringIO(logfileResult), usecols=['CHANGE_SET_NAME']) | |
for i, row in df.iterrows(): | |
sfdxCmd = f"sfdx force:source:retrieve -n '{row['CHANGE_SET_NAME']}' --targetusername={self.targetusername} --json" | |
try: | |
p = subprocess.Popen(sfdxCmd, shell=True, | |
stdout=subprocess.PIPE, encoding='utf-8') | |
result = p.communicate()[0].strip() | |
p.stdout.close() | |
except: | |
raise PopenError(f"Error with cmd: {sfdxCmd}. Error Msg: {sys.exc_info()[0]}") | |
findCmd = f"find '{row['CHANGE_SET_NAME']}' -name '*' -type f -print | awk -F/ '{{ print $(NF-1) \" - \" $NF }}'" | |
try: | |
p = subprocess.Popen(findCmd, shell=True, | |
stdout=subprocess.PIPE, encoding='utf-8') | |
result = p.communicate()[0].strip() | |
p.stdout.close() | |
except: | |
raise PopenError(f"Error with cmd: {findCmd}. Error Msg: {sys.exc_info()[0]}") | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment