def curl_check_url(config): from smashbox.utilities import oc_webdav_url import smashbox.curl, sys url = oc_webdav_url(remote_folder='', user_num=None) query="""<?xml version="1.0" ?> <d:propfind xmlns:d="DAV:"> <d:prop> </d:prop> </d:propfind> """ client = smashbox.curl.Client() exit_flag = False try: r = client.PROPFIND(url,query,depth=0,parse_check=False) if r.body_stream.getvalue() == "": print ("\n%s\n\nSMASHBOX_CHECK ERROR: %s, Empty response\nCHECK CONFIGURATION - oc_root, oc_ssl_enabled, oc_server, oc_server_shell_cmd etc.\nCHECK HEADERS e.g. for 302 - Location=%s\n"%(r.headers,r.rc,str(r.headers['Location']))) exit_flag = True else: import xml.etree.ElementTree as ET try: root = ET.fromstring(r.body_stream.getvalue()) if root.tag.find("error") != -1: raise Exception else: print "SMASHBOX_CHECK OK" except: print "SMASHBOX_CHECK ERROR: %s"%r.body_stream.getvalue() if str(r.body_stream.getvalue()).find("HTML") != -1: exit_flag=False else: exit_flag = True except Exception, e: exit_flag = True print e
def run_ocsync(local_folder, remote_folder="", n=None, user_num=None, option = None): """ Run the ocsync for local_folder against remote_folder (or the main folder on the owncloud account if remote_folder is None). Repeat the sync n times. If n given then n -> config.oc_sync_repeat (default 1). Option parameters is used in case of non-native engine and could specify specific behaviour of sync in the specific step. """ global ocsync_cnt,sync_exec_time_array from smashbox.utilities import reflection if n is None: n = config.oc_sync_repeat current_step = reflection.getCurrentStep() ocsync_cnt.setdefault(current_step,0) local_folder += '/' # FIXME: HACK - is a trailing slash really needed by 1.6 owncloudcmd client? for i in range(n): cmd = config.oc_sync_cmd+' '+local_folder+' '+oc_webdav_url('owncloud',remote_folder,user_num) + " >> "+config.rundir+"/%s-ocsync.step%02d.cnt%03d.log 2>&1"%(reflection.getProcessName(),current_step,ocsync_cnt[current_step]) sync_exec_time = sync_engine(cmd,option) sync_exec_time_array.append(sync_exec_time) logger.info('sync finished: %s s'%sync_exec_time) ocsync_cnt[current_step]+=1
def webdav_mkcol(path, silent=False, user_num=None): out="" if silent: # a workaround for super-verbose errors in case directory on the server already exists out = "> /dev/null 2>&1" runcmd('curl -k %s -X MKCOL %s %s'%(config.get('curl_opts',''),oc_webdav_url(remote_folder=path, user_num=user_num),out))
def webdav_delete(path, user_num=None): runcmd('curl -k %s -X DELETE %s '%(config.get('curl_opts',''),oc_webdav_url(remote_folder=path, user_num=user_num)))
def expect_webdav_exist(path, user_num=None): exitcode,stdout,stderr = runcmd('curl -s -k %s -XPROPFIND %s | xmllint --format - | grep NotFound | wc -l'%(config.get('curl_opts',''),oc_webdav_url(remote_folder=path, user_num=user_num))) exists = stdout.rstrip() == "0" error_check(exists, "Remote path %s exists but should not" % path)
def webdav_propfind_ls(path, user_num=None): runcmd('curl -s -k %s -XPROPFIND %s | xmllint --format -'%(config.get('curl_opts',''),oc_webdav_url(remote_folder=path, user_num=user_num)))