Created
January 25, 2012 23:21
-
-
Save sevennineteen/1679621 to your computer and use it in GitHub Desktop.
CQ5 tree activation example
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
import httplib2 | |
import urllib | |
import base64 | |
from html2text import html2text | |
#---------------------------------------------------------- | |
# INSTANCE-SPECIFIC CONSTANTS // customize before running | |
CQ_HOSTNAME = 'localhost' | |
CQ_SERVER = 'http://%s:4502' % CQ_HOSTNAME | |
USERNAME = 'admin' | |
PASSWORD = 'admin' | |
ACTIVATION_PATH = '/content/geometrixx/en' | |
ACTIVATION_ENDPOINT = '/etc/replication/treeactivation' | |
ACTIVATION_URL = CQ_SERVER + ACTIVATION_ENDPOINT | |
#---------------------------------------------------------- | |
def cq_auth_header(username, password): | |
"Converts user credentials to CQ-required request header." | |
return {'Authorization': 'Basic %s' % (base64.b64encode('%s:%s' % (username, password)))} | |
def stringify_params(params): | |
"Converts a dictionary of query params into a URL-encoded string." | |
return '&'.join(['%s=%s' % (urllib.quote(k), urllib.quote(v)) for k, v in params.items()]) | |
def activate_tree(url, headers, path): | |
"Performs tree activation from supplied path." | |
print 'Activating %s' % path | |
http = httplib2.Http() | |
data = { 'cmd': 'activate', | |
'ignoredeactivated': 'true', | |
'reactivate': 'true', | |
'onlymodified': 'true', | |
'path': path | |
} | |
headers.update({'Content-type': 'application/x-www-form-urlencoded'}) | |
response = http.request(url, headers=headers, method='POST', body=urllib.urlencode(data)) | |
print html2text(response[1]) | |
CQ_AUTH_HEADER = cq_auth_header(USERNAME, PASSWORD) | |
activate_tree(ACTIVATION_URL, CQ_AUTH_HEADER, ACTIVATION_PATH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment