'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[ 'PackageSubscriber'] += " AND MetadataPackageVersionId != '%s'" % excluded_versions[ 0] else: push_api.default_where[ 'PackageSubscriber'] += " AND MetadataPackageVersionId NOT IN %s" % "('" + "','".join(
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) print 'Push Request %s is queued for execution.' % request_id
'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' %
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)) # Query orgs for each version in the range individually to avoid query timeout errors with querying multiple versions for included_version in included_versions:
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 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 sys.exit(2)