def search_users(url, limit = 20): for i in range(limit): html = get_source( url + "/user/" + str(i)) red = re.findall(r"((users)\/(\w+))", html.url) if red: message (red[0][2],M_USER ,"OK")
def search_urls( url ): paths = [ "/user", "/node/add", ] for i in paths: html = get_source (url + str(i)) if html.status_code == 200: message(url + str(i), M_PATH ,"OK")
def test_error_view(self): '''Tests that 404 is returned when prompting non existing users''' nid=self.get_non_existing_id() message('Not existing id %d on User' %nid) r=self.client.get('/user/detail/%d'%nid) self.assertTrue(r.status_code, 404) r=self.client.get('/user/%d'%nid) self.assertTrue(r.status_code, 404)
def test_add_user(self): '''Tries to add a new user using the add form''' c=User.objects.count() d=self.get_standard_user() response=self.post_user(d) self.assertTrue(response.status_code!=200) nc=User.objects.count() if nc != c+1: message(response.content,2) self.assertEqual(nc,c+1,'User post failed')
def search ( url, project , version ): ban_f = ban_c = 0 #flags modules = (read_themes( version ), read_modules( version )) [ project == "modules"]; for i in modules: request_url_fail = url + "/" + ("themes", "modules") [ project == "modules"] + "/" + str(i) + "/CHANGELOG.txt" request_url_corr = url + "/sites/all/" + ("themes", "modules") [ project == "modules"] + "/" + str(i) + "/CHANGELOG.txt" if ban_f == 0: # search in /modules or /themes html = get_source(request_url_fail); if html.status_code == 200: ban_c = 1 message(" - " + request_url_fail , M_FILE , "OK") #found project search = re.findall(REG_GET_VERSION ,html.content) # find version if search: message("\t" + str(search[0][0] )+ str(search[0][1] ) + str(search[0][2] ), M_VERSION , "WARNING" ) if ban_c == 0: # search in /sites/all/ html = get_source(request_url_corr); if html.status_code == 200: ban_f = 1 message(request_url_corr ,M_FILE , "OK") # found project search = re.findall(REG_GET_VERSION ,html.content) # find version if search: message("\t" + str(search[0][0] )+ str(search[0][1] ) + str(search[0][2] ), M_VERSION , "WARNING" )
def test_not_add_user(self): '''Uses the form with invalid data and checks if the user is added or not''' message('Posting invalid users',1) c=User.objects.count() for k in self.get_standard_user().keys(): d=self.get_standard_user() d[k]='' message('Nulling field %s' %k) response=self.post_user(d) self.assertEqual(response.status_code,200) nc=User.objects.count() self.assertEqual(nc,c,response.content)
def test_timestamp(self): '''Checks that the timestamp is correctly updated''' ct = time() t=LastModified.objects.get(pk='User') message('Timestamps: %d >= %d' %(ct,t.timestamp)) self.assertGreaterEqual(ct,t.timestamp,'Table has timestamp in the future') #modify sleep(2) u=User() u.first_name='test1' u.save() t=LastModified.objects.get(pk='User') message('Timestamps %d >= %d' %(t.timestamp,ct)) self.assertGreaterEqual(t.timestamp,ct,'Timestamp not updated')
def sync(): r='v1/account_lead/' message('Requesting remote data...',1) b=remote_db.request(r) message('done!') #Sets are hashed, the "in" operator is O(1), it would be O(n) on a list uri_set = set() #Add remote users locally added=0 merged=0 for i in b['objects']: uri_set.add(i['resource_uri']) if len(User.objects.filter(resource_uri=i['resource_uri']))==0: #Tries to merge with local object using the email local_user=User.objects.filter(email=i['email']) if len(local_user)==1: message('Merging remote and local User %s'%i['email']) local_user[0].resource_uri=i['resource_uri'] local_user[0].save() merged+=1 else: #User does not exist locally User.create_from_dic(i) added+=1 message('Downloaded %d objects, added %d, merged %d' % (len(b['objects']),added,merged)) #Remove remote users locally to_delete = [] for i in User.objects.iterator(): #Using iterator because "all" would load the entire table in memory if i.resource_uri not in uri_set: to_delete.append(i) #I don't know how the iterator is implemented, i delete the objects later for safety message("Removing %d local users who don't exist remotely" % len(to_delete),1) map(lambda x: x.delete(force=True),to_delete)
def signal_handler(signal, frame): message ('Exit', "WARNING") sys.exit(0)
import re import simplejson from color import message import json try: import requests from requests import async except ImportError: message ("Check dependences: python-requests required", "-" , "ERROR") sys.exit(1) REG_GET_NAME_MODULE = r'<h2 class="title"><a href="\/project\/(\w+)"' REG_GET_VERSION = r"(\w)(\.x)(.*)" REG_GET_VERSION_D7 = r"(7)(\.x)(.*)" REG_GET_VERSION_D6 = r"(6)(\.x)(.*)" DRUPAL_MODULES = "http://drupal.org/project/modules" DRUPAL_THEMES = "http://drupal.org/project/themes" D6_URL_ARGS = {"page":0,"filters":"drupal_core:87 bs_project_sandbox:0","solrsort":"sis_project_release_usage desc"} D7_URL_ARGS = {"page":0,"filters":"drupal_core:103 bs_project_sandbox:0","solrsort":"sis_project_release_usage desc"} D8_URL_ARGS = {"page":0,"filters":"drupal_core:7234 bs_project_sandbox:0","solrsort":"sis_project_release_usage desc"} M_VERSION = " Version " M_FILE = " File " M_PROJECT = " Project "
from core import update from core import search from core import detect_version from core import search_users from core import search_urls from ops import opsx try: signal.signal(signal.SIGINT, signal_handler) o = opsx() if o.update_modules: update("modules", o.limit) message("Update modules. Done.",core.M_UPDATE, "OK") exit elif o.update_themes: update("themes", o.limit) message("Update themes. Done." ,core.M_UPDATE,"OK") exit if o.url != None: site_version = detect_version(o.url) message("Posible version " + str(site_version),core.M_VERSION, "WARNING") message("\t" + o.url + "/CHANGELOG.txt",core.M_FILE, "WARNING") if o.modules: