version_id = os.environ.get('VERSION') subscriber_where = os.environ.get('SUBSCRIBER_WHERE', None) # Add standard filters for only active orgs default_where = { 'PackageSubscriber': "OrgStatus = 'Active' AND InstalledStatus = 'i'" } # Append subscriber where if passed in environment if subscriber_where: default_where[ 'PackageSubscriber'] += " AND (%s)" % subscriber_where push_api = SalesforcePushApi(username, password, serverurl, default_where=default_where) # Get the target version version = push_api.get_package_version_objs("Id = '%s'" % version_id, limit=1)[0] # Add exclusion of all orgs running on newer releases newer_versions = version.get_newer_released_version_objs() excluded_versions = [ str(version.sf_id), ] for newer in newer_versions: excluded_versions.append(str(newer.sf_id)) if len(excluded_versions) == 1: push_api.default_where[
from push_api import SalesforcePushApi # Force UTF8 output reload(sys) sys.setdefaultencoding('UTF8') if __name__ == '__main__': try: username = os.environ.get('SF_USERNAME') password = os.environ.get('SF_PASSWORD') serverurl = os.environ.get('SF_SERVERURL') request_id = os.environ.get('PUSH_REQUEST') status = os.environ.get('PUSH_REQUEST_STATUS') push_api = SalesforcePushApi(username, password, serverurl) request = push_api.get_push_request_objs("Id = '%s'" % request_id, limit=1)[0] if request.status != status: ToolingPackagePushRequest = push_api.get_tooling_object('PackagePushRequest') print 'Updating status for Push Request %s from %s to %s' % (request_id, request.status, status) print ToolingPackagePushRequest.update(request_id, {'Status': status}) else: print 'Status for Push Request %s is already %s' % (request_id, status) except SystemExit: sys.exit(1) except: import traceback exc_type, exc_value, exc_traceback = sys.exc_info() print '-'*60 traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)
startTime = datetime.strptime(startTimeRaw, "%Y-%m-%dT%H:%M") # Example: 2016-10-19T10:00 else: startTime = None if not subscribers and not subscribers_file: raise ValueError('You must provide either the SUBSCRIBERS or SUBSCRIBERS_FILE environment variables') if subscribers: orgs = subscribers.split(',') else: f_orgs = open(subscribers_file, 'r') orgs = [] for org in f_orgs: orgs.append(org.strip()) push_api = SalesforcePushApi(username, password, serverurl) version = push_api.get_package_version_objs("Id = '%s'" % version, limit=1)[0] print 'Scheduling push upgrade for %s.%s to %s orgs' % (version.major, version.minor, len(orgs)) if startTime: print 'Scheduled start time: %s UTC' % startTime request_id = push_api.create_push_request(version, orgs, startTime) if len(orgs) > 1000: print "Delaying 30 seconds to allow all jobs to initialize..." time.sleep(30) print 'Push Request %s is populated, setting status to Pending to queue execution.' % request_id print push_api.run_push_request(request_id)
from push_api import SalesforcePushApi # Force UTF8 output reload(sys) sys.setdefaultencoding('UTF8') if __name__ == '__main__': try: username = os.environ.get('SF_USERNAME') password = os.environ.get('SF_PASSWORD') serverurl = os.environ.get('SF_SERVERURL') request_id = os.environ.get('PUSH_REQUEST') status = os.environ.get('PUSH_REQUEST_STATUS') push_api = SalesforcePushApi(username, password, serverurl) request = push_api.get_push_request_objs("Id = '%s'" % request_id, limit=1)[0] if request.status != status: print 'Updating status for Push Request %s from %s to %s' % (request_id, request.status, status) print push_api.sf.PackagePushRequest.update(request_id, {'Status': status}) else: print 'Status for Push Request %s is already %s' % (request_id, status) except SystemExit: sys.exit(1) except: import traceback exc_type, exc_value, exc_traceback = sys.exc_info() print '-'*60 traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) print '-'*60
if __name__ == '__main__': try: username = os.environ.get('SF_USERNAME') password = os.environ.get('SF_PASSWORD') serverurl = os.environ.get('SF_SERVERURL') push_request_id = os.environ.get('PUSH_REQUEST') subscriber_where = os.environ.get('SUBSCRIBER_WHERE', None) default_where = {'PackagePushRequest': "Id = '%s'" % push_request_id} if subscriber_where: default_where['PackageSubscriber'] = subscriber_where push_api = SalesforcePushApi(username, password, serverurl, lazy=['subscribers', 'jobs'], default_where=default_where) push_request = push_api.get_push_request_objs("Id = '%s'" % push_request_id, limit=1)[0] interval = 10 if push_request.status not in completed_statuses: print 'Push request is not yet complete. Polling for status every %s seconds until completion...' % interval i = 0 while push_request.status not in completed_statuses: if i == 10: print 'This is taking a while! Polling every 60 seconds...' interval = 60
username = os.environ.get('SF_USERNAME') password = os.environ.get('SF_PASSWORD') serverurl = os.environ.get('SF_SERVERURL') version_id = os.environ.get('VERSION') greater_than_version_id = os.environ.get('GREATER_THAN_VERSION', None) subscriber_where = os.environ.get('SUBSCRIBER_WHERE', None) # Add standard filters for only active orgs default_where = {'PackageSubscriber': "OrgStatus = 'Active' AND InstalledStatus = 'i'"} # Append subscriber where if passed in environment if subscriber_where: default_where['PackageSubscriber'] += " AND (%s)" % subscriber_where push_api = SalesforcePushApi(username, password, serverurl, default_where=default_where.copy()) # Get the target version version = push_api.get_package_version_objs("Id = '%s'" % version_id, limit=1)[0] orgs = [] if greater_than_version_id: # If working with a range of versions, use an inclusive search greater_than_version = push_api.get_package_version_objs("Id = '%s'" % greater_than_version_id, limit=1)[0] versions = version.get_older_released_version_objs(greater_than_version=greater_than_version) included_versions = [] for include_version in versions: included_versions.append(str(include_version.sf_id)) if not included_versions: raise ValueError('No versions found between version id %s and %s' % (version.version_number, greater_than_version.version_number))
startTime = None if not subscribers and not subscribers_file: raise ValueError( 'You must provide either the SUBSCRIBERS or SUBSCRIBERS_FILE environment variables' ) if subscribers: orgs = subscribers.split(',') else: f_orgs = open(subscribers_file, 'r') orgs = [] for org in f_orgs: orgs.append(org.strip()) push_api = SalesforcePushApi(username, password, serverurl) version = push_api.get_package_version_objs("Id = '%s'" % version, limit=1)[0] print 'Scheduling push upgrade for %s.%s to %s orgs' % ( version.major, version.minor, len(orgs)) if startTime: print 'Scheduled start time: %s UTC' % startTime request_id = push_api.create_push_request(version, orgs, startTime) if len(orgs) > 1000: print "Delaying 30 seconds to allow all jobs to initialize..." time.sleep(30) print 'Push Request %s is populated, setting status to Pending to queue execution.' % request_id
greater_than_version_id = os.environ.get('GREATER_THAN_VERSION', None) subscriber_where = os.environ.get('SUBSCRIBER_WHERE', None) # Add standard filters for only active orgs default_where = { 'PackageSubscriber': "OrgStatus = 'Active' AND InstalledStatus = 'i'" } # Append subscriber where if passed in environment if subscriber_where: default_where[ 'PackageSubscriber'] += " AND (%s)" % subscriber_where push_api = SalesforcePushApi(username, password, serverurl, default_where=default_where.copy()) # Get the target version version = push_api.get_package_version_objs("Id = '%s'" % version_id, limit=1)[0] orgs = [] if greater_than_version_id: # If working with a range of versions, use an inclusive search greater_than_version = push_api.get_package_version_objs( "Id = '%s'" % greater_than_version_id, limit=1)[0] versions = version.get_older_released_version_objs( greater_than_version=greater_than_version) included_versions = []
username = os.environ.get('SF_USERNAME') password = os.environ.get('SF_PASSWORD') serverurl = os.environ.get('SF_SERVERURL') version_id = os.environ.get('VERSION') greater_than_version_id = os.environ.get('GREATER_THAN_VERSION', None) subscriber_where = os.environ.get('SUBSCRIBER_WHERE', None) # Add standard filters for only active orgs default_where = {'PackageSubscriber': "OrgStatus = 'Active' AND InstalledStatus = 'i'"} # Append subscriber where if passed in environment if subscriber_where: default_where['PackageSubscriber'] += " AND (%s)" % subscriber_where push_api = SalesforcePushApi(username, password, serverurl, default_where=default_where) # Get the target version version = push_api.get_package_version_objs("Id = '%s'" % version_id, limit=1)[0] if greater_than_version_id: # If working with a range of versions, use an inclusive search greater_than_version = push_api.get_package_version_objs("Id = '%s'" % greater_than_version_id, limit=1)[0] versions = version.get_older_released_version_objs(greater_than_version=greater_than_version) included_versions = [] for include_version in versions: included_versions.append(str(include_version.sf_id)) if not included_versions: raise ValueError('No versions found between version id %s and %s' % (version.version_number, greater_than_version.version_number)) if len(included_versions) == 1:
from push_api import SalesforcePushApi # Force UTF8 output reload(sys) sys.setdefaultencoding('UTF8') if __name__ == '__main__': try: username = os.environ.get('SF_USERNAME') password = os.environ.get('SF_PASSWORD') serverurl = os.environ.get('SF_SERVERURL') request_id = os.environ.get('PUSH_REQUEST') status = os.environ.get('PUSH_REQUEST_STATUS') push_api = SalesforcePushApi(username, password, serverurl) request = push_api.get_push_request_objs("Id = '%s'" % request_id, limit=1)[0] if request.status != status: print 'Updating status for Push Request %s from %s to %s' % ( request_id, request.status, status) print push_api.sf.PackagePushRequest.update( request_id, {'Status': status}) else: print 'Status for Push Request %s is already %s' % (request_id, status) except SystemExit: sys.exit(1) except: import traceback
major = version_parts[0] if len(version_parts) == 2: minor = version_parts[1] if minor.find('Beta') != -1: state = 'Beta' minor, build = minor.replace(' (Beta ', ',').replace(')', '').split(',') if len(version_parts) > 2: minor = version_parts[1] patch = version_parts[2] if patch.find('Beta') != -1: state = 'Beta' patch, build = minor.replace(' (Beta ', ',').replace(')', '').split(',') push_api = SalesforcePushApi(username, password, serverurl) package = push_api.get_package_objs("NamespacePrefix = '%s'" % namespace, limit=1)[0] version_where = "ReleaseState = '%s' AND MajorVersion = %s AND MinorVersion = %s" % ( state, major, minor) if patch: version_where += " AND PatchVersion = %s" % patch if state == 'Beta' and build: version_where += " AND BuildNumber = %s" % build version = push_api.get_package_version_objs(version_where, limit=1)[0] print version.sf_id
from push_api import SalesforcePushApi # Force UTF8 output reload(sys) sys.setdefaultencoding('UTF8') if __name__ == '__main__': try: username = os.environ.get('SF_USERNAME') password = os.environ.get('SF_PASSWORD') serverurl = os.environ.get('SF_SERVERURL') request_id = os.environ.get('PUSH_REQUEST') status = os.environ.get('PUSH_REQUEST_STATUS') push_api = SalesforcePushApi(username, password, serverurl) request = push_api.get_push_request_objs("Id = '%s'" % request_id, limit=1)[0] if request.status != status: ToolingPackagePushRequest = push_api.get_tooling_object( 'PackagePushRequest') print 'Updating status for Push Request %s from %s to %s' % ( request_id, request.status, status) print ToolingPackagePushRequest.update(request_id, {'Status': status}) else: print 'Status for Push Request %s is already %s' % (request_id, status) except SystemExit: sys.exit(1)