Provide reviewboard-extensions interface.
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
reviewboard (Juju Charms Collection) |
Triaged
|
Low
|
Unassigned |
Bug Description
The key one for me would be a "reviewboard-
provides:
reviewboard-
interface: reviewboard-
gets: [settings] # a mapping of names to values.
The charm would add two hooks:
* reviewboard-
* reviewboard-
"settings" could conceivably go in a "reviewboard" interface or even a generic "settings" interface that would perform that "-relation-changed" role:
provides:
reviewboard: # or settings
interface: reviewboard # or settings
gets: [settings]
A plain "reviewboard" interface would probably be a good idea regardless. It would at least allow consumers to know when reviewboard was ready to go.
Changed in reviewboard (Juju Charms Collection): | |
status: | New → Triaged |
importance: | Undecided → Low |
I imagine that the hook code would be something like this:
INJECTED_WARNING = """ ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- -- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- --
#------
# The following is the import code for the settings directory injected by Juju
#------
"""
PKG = '_juju_ extensions_ settings' join(os. path.dirname( path_to_ rb_settings_ py), PKG)
PKG_DIR = os.path.
def open_settings( extname) : join(PKG_ DIR, extname + '_settings.py') exists( filename) :
filename = os.path.
try:
return open(filename, 'r+')
except IOError:
if os.path.
raise
if not os.path. exists( PKG_DIR) :
os.mkdir( PKG_DIR) to_rb_settings_ py, 'a') as settings_py:
settings_ py.write( INJECTED_ WARNING)
settings_ py.write( "from {} import *".format(PKG))
with open(path_
extfile = open(filename, 'w+')
with open(os. path.join( PKG_DIR, '__init__.py'), 'a') as initfile:
initfile. write(' from .{} import *\n'.format( extname) )
return extfile
def set_settings( extname, settings):
# inspired by what the django charm does.
lines = [] .format( name, value)
ast. literal_ eval(line)
hookenv. log('bad setting: {!r}'.format(line))
lines. append( line)
for name, value in settings.items():
line = '{} = {!r}\n'
try:
except SyntaxError:
return # fail?
with open_settings( extname) as extfile:
extfile. writelines( lines)
extfile. truncate( )
# Force RB to reload settings.py.i path_to_ rb_settings_ py)
touch(
def clear_settings( extname= None): join(PKG_ DIR, extname + '_settings.py') exists( filename) :
os. remove( filename) extname) path.join( PKG_DIR, '__init__.py'), 'r+') as initfile:
last = 0
if line == extline:
break
last += len(line)
lines = []
lines. append( line)
initfile. seek(last)
initfile. writelines( lines)
initfile. truncate( ) exists( PKG_DIR) :
os. rmdir(PKG_ DIR) rb_settings_ py?
if extname is not None:
filename = os.path.
if os.path.
extline = 'from .{} import *\n'.format(
with open(os.
for line in initfile:
for line in initfile:
else:
if os.path.
# remove import from path_to_
def related_name(): related_ units() [0] '/')[0]
"""Return the name of the extension in the current relation."""
# We just use the service name.
unit = hookenv.
service = unit.partition(
return service
def _handle_ relation_ settings( ): relation_ get('settings' )
requested = hookenv.
if not requested:
# no settings to add
return
name = related_name() relation_ get('_all_ settings' ) or {} update( requested)
set_settings( name, settings)
hookenv. log("could not update reviewboard settings: {}".format(e))
settings = hookenv.
settings.
try:
except Exception as e:
# hooks
@hooks. hook('reviewboa rd-extensions- relation- joined' )
def re...