예제 #1
0
파일: web.py 프로젝트: fantix/ArchRepo
 def login(self, redirect_url=None):
     if not redirect_url:
         redirect_url = cherrypy.request.headers.get('REFERER', None)
     if not redirect_url:
         redirect_url = config.get('web', 'external-base-url')
     if not self.auth.getUserInfo():
         try:
             self.auth.login()
         except AuthError:
             tmpl = self._env.get_template('login.html')
             return tmpl.render(
                 base_url=config.get('web', 'external-base-url').rstrip('/'),
                 flux_url=config.get('flux-sso', 'login-url'),
                 redirect_url=redirect_url)
         else:
             logging.debug('Logged in successfully')
     raise cherrypy.HTTPRedirect(redirect_url or '/')
예제 #2
0
파일: web.py 프로젝트: fantix/ArchRepo
 def logout(self, redirect_url=None):
     if not redirect_url:
         redirect_url = cherrypy.request.headers.get('REFERER', None)
     if not redirect_url:
         redirect_url = config.get('web', 'external-base-url')
     if self.auth.getUserInfo():
         self.auth.logout()
     if redirect_url:
         raise cherrypy.HTTPRedirect(redirect_url)
예제 #3
0
파일: repo.py 프로젝트: fantix/ArchRepo
    def my_init(self, **kwargs):
        self._started_event = AsyncResult()
        self._repo_lock = defaultdict(RLock)
        self._same_pkg_locks = defaultdict(RLock)
        self._ignored_move_events = set()
        self._move_events = {}

        self._pool = kwargs.get('pool')

        self._repo_dir = config.get('repository', 'path')
        self._db_name = config.get('repository', 'name') + '.db.tar.gz'
        self._verify = config.xgetbool('repository', 'verify-tarball', True)
        self._auto_rename = config.xgetbool('repository', 'auto-rename', True)
        self._command_add = config.xget('repository', 'command-add',
                                        default='repo-add')
        self._command_remove = config.xget('repository', 'command-remove',
                                        default='repo-remove')
        self._command_fuser = config.xget('repository', 'command-fuser',
                                          default='fuser')
        self._command_pkginfo = os.path.join(
            os.environ.get('ARCHREPO_PREFIX', sys.prefix), 'bin',
            'read_pkginfo.py')
        self._semaphore = Semaphore(
            config.xgetint('repository', 'concurrent-jobs', default=256))
예제 #4
0
파일: repo.py 프로젝트: fantix/ArchRepo
 def _serve(self):
     ctx = getZmqContext()
     self.socket = ctx.socket(zmq.PULL)
     try:
         try:
             self.socket.bind(config.get('repository', 'management-socket'))
         except zmq.ZMQError:
             self._started_event.set(False)
         else:
             self._started_event.set(True)
             while True:
                 parts = self.socket.recv_multipart()
                 handler = getattr(self, 'handle_' + parts[0], None)
                 if handler:
                     gevent.spawn(self._handle_wrapper, handler, *parts[1:])
     finally:
         self.socket.close()
예제 #5
0
import os

from archrepo import config
from archrepo.db_pool import buildPool
from archrepo.repo import Processor
from archrepo.repo import FakeProcessor


files = set()
def _walker(arg, dirname, fnames):
    for name in fnames:
        if name.endswith('.pkg.tar.gz') or name.endswith('.pkg.tar.xz'):
            _file = os.path.abspath(os.path.join(dirname, name))
            if not os.path.islink(_file):
                files.add(_file)
os.path.walk(config.get('repository', 'path'), _walker, None)

known = set()
pool = buildPool()
with pool.cursor() as cur:
    cur.execute('SELECT file_path FROM packages')
    for path, in cur.fetchall():
        if path:
            known.add(path.encode('utf-8'))

local = True
p = Processor(pool=pool)
p.serve()

if p.serving:
    print 'Repo processor is up'
예제 #6
0
 def __init__(self, pevent=None, **kargs):
     super(PrintEvents, self).__init__(pevent, **kargs)
     self._socket = getZmqContext().socket(zmq.PUSH)
     self._socket.connect(config.get('repository', 'management-socket'))
예제 #7
0
    def __init__(self, pevent=None, **kargs):
        super(PrintEvents, self).__init__(pevent, **kargs)
        self._socket = getZmqContext().socket(zmq.PUSH)
        self._socket.connect(config.get('repository', 'management-socket'))

    def process_default(self, event):
        self._socket.send_multipart((
            'inotify',
            str(event.mask),
            str(event.cookie) if event.mask & (0x00000040 | 0x00000080) else '',
            str(event.dir),
            event.pathname))


if __name__ == '__main__':
    path = config.get('repository', 'path')

    # watch manager instance
    wm = WatchManager()

    # notifier instance and init
    notifier = Notifier(wm, default_proc_fun=PrintEvents())

    s = """
    FLAG_COLLECTIONS = {'OP_FLAGS': {
        'IN_ACCESS'        : 0x00000001,  # File was accessed
        'IN_MODIFY'        : 0x00000002,  # File was modified
        'IN_ATTRIB'        : 0x00000004,  # Metadata changed
        'IN_CLOSE_WRITE'   : 0x00000008,  # Writable file was closed
        'IN_CLOSE_NOWRITE' : 0x00000010,  # Unwritable file closed
        'IN_OPEN'          : 0x00000020,  # File was opened
예제 #8
0
파일: repo.py 프로젝트: fantix/ArchRepo
 def __init__(self):
     ctx = getZmqContext()
     self.socket = ctx.socket(zmq.PUSH)
     self.socket.connect(config.get('repository', 'management-socket'))
예제 #9
0
파일: web.py 프로젝트: fantix/ArchRepo
 def __init__(self, pool):
     super(FluxAuth, self).__init__(pool)
     self._hmac_key = config.get('flux-sso', 'key')
     self._sso_api_url = config.get('flux-sso', 'api')
     self._sso_cookie = config.xget('flux-sso', 'cookie', default='xsdauth')
예제 #10
0
파일: web.py 프로젝트: fantix/ArchRepo
    def query(self, sort=None, arch=None, maintainer=None, q=None, limit=None,
              page=None, flagged=None, last_update=None):
        userinfo = self.auth.getUserInfo()

        sql = 'SELECT %s FROM packages' % ', '.join(FIELDS)
        sort_list = []
        where_list = ['latest']
        desc = True
        values = {}

        if arch is not None:
            if not isinstance(arch, list):
                arch = [arch]
            where_list.append('arch IN %(arch)s')
            values['arch'] = tuple(arch)
        else:
            arch = ()

        if last_update is not None and last_update.strip():
            where_list.append('last_update > %(last_update)s')
            values['last_update'] = last_update
        else:
            last_update = ''

        if flagged == '1':
            where_list.append('flag_date IS NOT NULL')
        elif flagged == '2':
            where_list.append('flag_date IS NULL')
        else:
            flagged = '0'

        if maintainer is not None and maintainer.isdigit():
            if int(maintainer):
                where_list.append('owner=%(owner)s')
                values['owner'] = int(maintainer)
            else:
                where_list.append('owner IS NULL')

        if sort:
            for part in sort.lower().split(','):
                if part in ('last_update', 'name', 'arch', 'flag_date'):
                    sort_list.append(part)
                if part in ('name', 'arch', 'asc'):
                    desc = False
                if part in ('desc',):
                    desc = True
        if not sort_list:
            sort = 'last_update'
            sort_list.append(sort)
            desc = True

        if q is not None and q.strip():
            sql = ', '.join((sql, "to_tsquery(%(lang)s, %(q)s) query"))
            values['lang'] = 'english'
            values['q'] = '&'.join(q.split())
            where_list.append('searchable @@ query')
            sort_list.append('ts_rank_cd(searchable, query)')
            desc = True
        else:
            q = ''

        if where_list:
            sql = ' WHERE '.join((sql, ' AND '.join(where_list)))

        if sort_list:
            sql = ' ORDER BY '.join((sql, ', '.join(sort_list)))
            if desc:
                sql = ' '.join((sql, 'DESC'))

        if limit not in AVAILABLE_LIMITS[1:]:
            limit = AVAILABLE_LIMITS[0]
        if limit != 'all':
            #noinspection PyUnresolvedReferences
            if 'sub_cursor_pool' in cherrypy.session:
                #noinspection PyUnresolvedReferences
                cpool = cherrypy.session['sub_cursor_pool']
            else:
                cpool = SubCursorPool(
                    self.cursorPool,
                    config.xgetint('web', 'concurrent-queries-per-session', 1))
                #noinspection PyUnresolvedReferences
                cherrypy.session['sub_cursor_pool'] = cpool

            cursor = cpool.getCursor(self.pool, sql % values, sql, values)
            count = cursor.count
            all_pages = int(math.ceil(float(count) / int(limit)))
            if page is not None and page.isdigit():
                page = min(all_pages, max(1, int(page)))
            else:
                page = 1
            offset = (page - 1) * int(limit)
            result = cursor.fetch(int(limit), offset)
        else:
            page = 1
            all_pages = 1
            with self.pool.cursor() as cur:
                logging.debug('SQL: %s, VALUES: %r', sql, values)
                cur.execute(sql, values)
                result = cur.fetchall()
            count = len(result)
        with self.pool.cursor() as cur:
            cur.execute('SELECT id, username FROM users')
            users = [(None, self.gettext('All')), ('0', self.gettext('Orphan'))]
            for val, label in cur.fetchall():
                users.append((str(val), label))
            users_dict = dict(users)

        result = [dict(zip(FIELDS, x)) for x in result]
        for row in result:
            row['last_update'] = format_date(row['last_update'])
            row['flag_date'] = ('' if row['flag_date'] is None else
                                format_date(row['flag_date']))
            row['maintainer'] = users_dict.get(str(row['owner'] or '0'))
        parts = cherrypy.request.query_string.split('&')
        pager = '&'.join([x for x in parts if not x.startswith('page=')] + ['page='])
        sorter = '&'.join([x for x in parts if not x.startswith('sort=')] + ['sort='])
        tmpl = self._env.get_template('packages.html')
        return tmpl.render(
            packages=result, userinfo=userinfo, q=q, arch=arch,
            last_update=last_update, flagged=flagged, page=page, count=count,
            all_pages=all_pages, limit=limit, all_limits=AVAILABLE_LIMITS,
            pager=pager, sorter=sorter, maintainer=maintainer, users=users,
            base_url=config.get('web', 'external-base-url').rstrip('/'),
            title=config.get('web', 'title'),
            favicon=config.get('web', 'favicon'),
            all_arch=('any', 'i686', 'x86_64'))