#367 Make a few things easier for new contributors
Merged 6 years ago by abompard. Opened 6 years ago by abompard.
abompard/fedora-hubs easier-onboarding  into  develop

file modified
+2 -2
@@ -7,11 +7,11 @@ 

  

  * You can type `workon hubs` to enter a configured Python virtualenv

  

- * Run `hup` to start the flask webserver

+ * Run `honcho start` to start the webserver and the backend services.

  

  * Run `hreset` to delete the database and repopulate it

  

- Once you run `hup` you can navigate to http://localhost:5000/

+ Once you run `honcho start` you can navigate to http://localhost:5000/

  in your browser.

  

  Happy hacking!

@@ -0,0 +1,23 @@ 

+ - name: Install Fedora Hubs development packages

+   dnf: name={{ item }} state=present

+   with_items:

+     - gcc

+     - gcc-c++

+     - libffi-devel

+     - openssl-devel

+     - python-sphinx

+     - python2-devel

+     - python3-devel

+     - python3-honcho

+     - python3-tox

+     - redhat-rpm-config

+     - sqlite-devel

+ 

+ - name: Install a custom bashrc

+   template: src=bashrc dest=/home/{{ main_user }}/.bashrc

+ 

+ - name: Install Honcho's env file

+   template: src=honcho-env dest={{ hubs_base_dir }}/.env

+ 

+ - name: Install Honcho's procfile

+   template: src=honcho-procfile dest={{ hubs_base_dir }}/Procfile

@@ -14,21 +14,6 @@ 

      - python-virtualenv

      - python3-flask-oidc

  

- - name: Install Fedora Hubs development packages

-   dnf: name={{ item }} state=present

-   with_items:

-     - gcc

-     - gcc-c++

-     - libffi-devel

-     - openssl-devel

-     - python-sphinx

-     - python2-devel

-     - python3-devel

-     - python3-tox

-     - redhat-rpm-config

-     - sqlite-devel

-   when: hubs_dev_mode

- 

  - name: Install the distribution versions of requirements.txt

    dnf: name={{ item }} state=present

    with_items:
@@ -56,12 +41,6 @@ 

      - python-retask

  

  

- # Add various helpful configuration files

- - name: Install a custom bashrc

-   template: src=bashrc dest=/home/{{ main_user }}/.bashrc

-   when: hubs_dev_mode

- 

- 

  # Create directory structure

  

  - name: Create the directory structure
@@ -169,33 +148,16 @@ 

  - name: Disable the system-wide fedmsg-hub

    service: name=fedmsg-hub state=stopped enabled=no

  

- - name: Install the service files

-   template:

-     src: "{{ item }}.service"

-     dest: /etc/systemd/system/{{ item }}.service

-   with_items:

-     - hubs-triage@

-     - hubs-worker@

-     - hubs-sse

-     - hubs-fedmsg-hub

-   register: service_installed

- 

- - name: reload systemd

-   command: systemctl daemon-reload

-   when: service_installed|changed

- 

- - name: Start and enable the services

+ - name: Start and enable the common services

    service: name={{ item }} state=started enabled=yes

    with_items:

      - redis

-     - hubs-triage@1

-     - hubs-triage@2

-     - hubs-worker@1

-     - hubs-worker@2

-     - hubs-sse

-     - hubs-fedmsg-hub

  

  

- # Webserver

- - include: webserver.yml

+ # Include mode-specific tasks

+ 

+ - include: dev.yml

+   when: hubs_dev_mode

+ 

+ - include: prod.yml

    when: not hubs_dev_mode

@@ -0,0 +1,26 @@ 

+ - name: Install the service files

+   template:

+     src: "{{ item }}.service"

+     dest: /etc/systemd/system/{{ item }}.service

+   with_items:

+     - hubs-triage@

+     - hubs-worker@

+     - hubs-sse

+     - hubs-fedmsg-hub

+   register: service_installed

+ 

+ - name: reload systemd

+   command: systemctl daemon-reload

+   when: service_installed|changed

+ 

+ - name: Start and enable the services in prod mode

+   service: name={{ item }} state=started enabled=yes

+   with_items:

+     - hubs-triage@1

+     - hubs-triage@2

+     - hubs-worker@1

+     - hubs-worker@2

+     - hubs-sse

+     - hubs-fedmsg-hub

+ 

+ - include: webserver.yml

@@ -23,14 +23,9 @@ 

      cd {{ hubs_code_dir }}

  }

  

- hup() {

-     source {{ hubs_venv_dir }}/bin/activate

-     pushd {{ hubs_code_dir }}

-     FLASK_DEBUG=1 flask run --host 0.0.0.0 --port 5000

- }

+ alias hup="pushd ~ ; honcho start ; popd"

  

  hreset() {

-     source {{ hubs_venv_dir }}/bin/activate

      {% if hubs_db_type == "postgresql" %}

      sudo -u postgres dropdb hubs

      sudo -u postgres createdb -O hubs hubs
@@ -39,7 +34,6 @@ 

      {% endif %}

      rm {{ hubs_var_dir }}/cache.db

      pushd {{ hubs_code_dir }}

-     python populate.py

+     {{ hubs_venv_dir }}/bin/python populate.py

      popd

-     deactivate

  }

@@ -0,0 +1,3 @@ 

+ FLASK_DEBUG=1

+ FLASK_APP={{ hubs_code_dir }}/hubs/app.py

+ HUBS_CONFIG={{ hubs_conf_dir }}/hubs_config.py

@@ -0,0 +1,6 @@ 

+ web: {{ hubs_venv_dir }}/bin/python /usr/bin/flask run --host 0.0.0.0 --port 5000

+ triage: {{ hubs_venv_dir }}/bin/fedora-hubs-triage

+ worker: {{ hubs_venv_dir }}/bin/fedora-hubs-worker

+ sse: {{ hubs_venv_dir }}/bin/python /usr/bin/twistd -l - --pidfile= -ny {{ hubs_code_dir }}/hubs/backend/sse_server.tac

:thumbsup:

+ fedmsg_hub: {{ hubs_venv_dir }}/bin/python /usr/bin/fedmsg-hub

+ js_build: cd {{ hubs_code_dir }}/hubs/static/client && npm run dev

@@ -27,3 +27,12 @@ 

          state: link

          path: /home/{{ main_user }}/devel

          src: /srv/hubs/fedora-hubs

+ 

+     - name: Make a symlink to the Honcho files

+       file:

+         state: link

+         path: /home/{{ main_user }}/{{ item }}

+         src: /srv/hubs/{{ item }}

+       with_items:

+       - Procfile

+       - .env

file modified
+25 -8
@@ -28,6 +28,7 @@ 

  import operator

  import os

  import random

+ from collections import defaultdict

  

  import bleach

  import sqlalchemy as sa
@@ -346,12 +347,18 @@ 

          return 12 - self.left_width

  

  

- def _widget_config_default(context):

-     widget_name = context.current_parameters['plugin']

-     widget = hubs.widgets.registry[widget_name]

-     return json.dumps(dict([

-         (param.name, param.default) for param in widget.get_parameters()

-         ]))

+ class SpecificDefaultDict(defaultdict):

+     """A more specific version of defaultdict.

+ 

+     This class behaves like defaultdict, but calls the ``default_factory`` with

+     the key as first argument.

+     """

+ 

+     def __missing__(self, key):

+         if self.default_factory is None:

+             return super(SpecificDefaultDict, self).__missing__(key)

+         self[key] = self.default_factory(key)

+         return self[key]

  

  

  class Widget(ObjectAuthzMixin, BASE):
@@ -364,7 +371,7 @@ 

      plugin = sa.Column(sa.String(50), nullable=False)

      created_on = sa.Column(sa.DateTime, default=datetime.datetime.utcnow)

      hub_id = sa.Column(sa.String(50), sa.ForeignKey('hubs.name'))

-     _config = sa.Column(sa.Text, default=_widget_config_default)

+     _config = sa.Column(sa.Text, default="{}")

  

      index = sa.Column(sa.Integer, nullable=False)

      left = sa.Column(sa.Boolean, nullable=False, default=False)
@@ -388,7 +395,17 @@ 

  

      @property

      def config(self):

-         return json.loads(self._config)

+         def get_default(key):

+             for param in self.module.get_parameters():

+                 if key == param.name:

+                     break

+             else:

+                 raise KeyError("No such parameter")

+             return param.default

+ 

+         value = SpecificDefaultDict(get_default)

+         value.update(json.loads(self._config))

+         return value

  

      @config.setter

      def config(self, config):

file modified
+4
@@ -9,6 +9,7 @@ 

  from importlib import import_module

  from .caching import CachedFunction

  from .view import WidgetView

+ from .validators import Validator

  

  

  log = logging.getLogger(__name__)
@@ -46,6 +47,9 @@ 

              setattr(self, name, kwargs.pop(name, None))

          for name in kwargs:

              raise TypeError("Invalid attribute: %s" % name)

+         # Set default validator

+         if self.validator is None:

+             self.validator = Validator

  

  

  class Widget(object):

file modified
+1
@@ -55,6 +55,7 @@ 

          return "|".join([

              str(self.instance.idx),

              self.__class__.__name__,

+             str(dict(self.instance.config)),

          ]).encode('utf-8')

  

      def get_data(self):

file modified
+1 -1
@@ -69,7 +69,7 @@ 

          Args:

              instance (hubs.models.Widget): the widget instance.

          """

-         raise NotImplementedError

+         return {}

  

      def get_template(self):

          """