def collections( request ): """ We are displaying collection status vis-a-vis the project Gitolite server. It takes too long to run git-status on every repo so, if repo statuses are not cached they will be updated by jQuery after page load has finished. """ collections = [] collection_status_urls = [] for o in gitolite.get_repos_orgs(): repo,org = o.split('-') colls = [] for coll in commands.collections_local(settings.MEDIA_BASE, repo, org): if coll: coll = os.path.basename(coll) c = coll.split('-') repo,org,cid = c[0],c[1],c[2] collection = Collection.from_json(Collection.collection_path(request,repo,org,cid)) colls.append(collection) gitstatus = collection.gitstatus() if gitstatus and gitstatus.get('sync_status'): collection.sync_status = gitstatus['sync_status'] else: collection_status_urls.append( "'%s'" % collection.sync_status_url()) collections.append( (o,repo,org,colls) ) # load statuses in random order random.shuffle(collection_status_urls) return render_to_response( 'webui/collections/index.html', {'collections': collections, 'collection_status_urls': ', '.join(collection_status_urls),}, context_instance=RequestContext(request, processors=[]) )
def collections( request ): """ We are displaying collection status vis-a-vis the project Gitolite server. It takes too long to run git-status on every repo so, if repo statuses are not cached they will be updated by jQuery after page load has finished. """ collections = [] collection_status_urls = [] for object_id in gitolite.get_repos_orgs(): identifier = Identifier(object_id) # TODO Identifier: Organization object instead of repo and org repo,org = identifier.parts.values() collection_paths = Collection.collection_paths(settings.MEDIA_BASE, repo, org) colls = [] for collection_path in collection_paths: if collection_path: identifier = Identifier(path=collection_path) collection = Collection.from_identifier(identifier) colls.append(collection) gitstatus = collection.gitstatus() if gitstatus and gitstatus.get('sync_status'): collection.sync_status = gitstatus['sync_status'] else: collection_status_urls.append( "'%s'" % collection.sync_status_url()) collections.append( (object_id,repo,org,colls) ) # load statuses in random order random.shuffle(collection_status_urls) return render_to_response( 'webui/collections/index.html', {'collections': collections, 'collection_status_urls': ', '.join(collection_status_urls),}, context_instance=RequestContext(request, processors=[]) )
def gitstatus_update( collection_path ): if not os.path.exists(settings.MEDIA_BASE): raise Exception('base_dir does not exist. No Store mounted?: %s' % settings.MEDIA_BASE) if not os.path.exists(gitstatus.queue_path(settings.MEDIA_BASE)): queue = gitstatus.queue_generate( settings.MEDIA_BASE, gitolite.get_repos_orgs() ) gitstatus.queue_write(settings.MEDIA_BASE, queue) return gitstatus.update(settings.MEDIA_BASE, collection_path)
def gitstatus_update_store(): if not os.path.exists(settings.MEDIA_BASE): raise Exception('base_dir does not exist. No Store mounted?: %s' % settings.MEDIA_BASE) if not os.path.exists(gitstatus.queue_path(settings.MEDIA_BASE)): queue = gitstatus.queue_generate( settings.MEDIA_BASE, gitolite.get_repos_orgs() ) gitstatus.queue_write(settings.MEDIA_BASE, queue) return gitstatus.update_store( base_dir=settings.MEDIA_BASE, delta=60, minimum=settings.GITSTATUS_INTERVAL, )
def inner(request, *args, **kwargs): readable = False # if we can get list of collections, storage must be readable basepath = settings.MEDIA_BASE if not os.path.exists(basepath): msg = 'ERROR: Base path does not exist: %s' % basepath messages.error(request, msg) return HttpResponseRedirect(reverse('storage-required')) # realpath(MEDIA_BASE) indicates which Store is mounted basepathreal = os.path.realpath(settings.MEDIA_BASE) try: basepath_listdir = os.listdir(basepath) except OSError: basepath_listdir = [] if not basepath_listdir: messages.error(request, 'ERROR: Base path exists but is not listable (probably the drive is not mounted).') return HttpResponseRedirect(reverse('storage-required')) repos_orgs = gitolite.get_repos_orgs() if repos_orgs: # propagate error if (type(repos_orgs) == type('')) and ('error' in repos_orgs): messages.error(request, repos_orgs) return HttpResponseRedirect(reverse('storage-required')) elif (type(repos_orgs) == type([])): repo,org = repos_orgs[0].split('-') try: collections = models.Collection.collection_paths(settings.MEDIA_BASE, repo, org) readable = True except: messages.error(request, 'ERROR: Could not get collections list.') else: # If there are no repos/orgs, it may mean that the ddr user # is missing its SSH keys. messages.error(request, STORAGE_MESSAGES['NO_REPOS_ORGS']) if not readable: logger.debug('storage not readable') status,msg = commands.status(basepath) logger.debug('storage status: %s' % status) logger.debug('storage msg: %s' % msg) remount_uri = request.META.get('PATH_INFO',None) request.session[settings.REDIRECT_URL_SESSION_KEY] = remount_uri if msg == 'unmounted': messages.debug(request, '<b>{}</b>: {}'.format(settings.REDIRECT_URL_SESSION_KEY, remount_uri)) return HttpResponseRedirect(reverse('storage-remount0')) else: messages.error(request, STORAGE_MESSAGES['ERROR']) return HttpResponseRedirect(reverse('storage-required')) return func(request, *args, **kwargs)