gnewsense-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnewsense-dev] Debderive


From: Sam Geeraerts
Subject: Re: [Gnewsense-dev] Debderive
Date: Sun, 12 Feb 2012 14:17:33 +0100
User-agent: Thunderbird 2.0.0.24 (X11/20101029)

Stayvoid wrote:
Hi!

1.
os.system(' '.join(('reprepro --noskipold -Vb', self._base_path, command)))

# Could you explain how these functions work?
# And what will we get as a result?
# I was trying to follow the code, but I've got lost.

It results in a command like:

reprepro --noskipold -Vb /data/gnewsense/ update

# It should be something like this:
# os.system(' '.join((reprepro --noskipold -Vb',
main_conf['base_dir'], command)))
# But I don't know the value of the 'base_dir' key and the syntax of
os.system is unfamiliar to me.

base_dir is defined in the yaml configuration file (/etc/debderiver/debderive.yaml).

os.system executes a shell command [1].

# Here is my attempt to understand it.

class Reprepro(object):
    # skipped
    def __init__(self, op_sys):
        self._base_path = op_sys.base_dir

rr = Reprepro(conf)

# self._base_path = main_conf['base_dir']

conf = parse(CONF_DIR_PATH)

# self.name = main_conf['os']
# self.description = main_conf['description']
# self.base_dir = main_conf['base_dir']

CONF_DIR_PATH = '/etc/debderiver'

def parse(conf_dir_path):
        conf_file_path = os.path.join(conf_dir_path, MAIN_CONF_FILE_NAME)
        # skipped
        opsys = OperatingSystem(main_conf['os'], main_conf['description'], \
                                    main_conf['base_dir'])

MAIN_CONF_FILE_NAME = 'debderiver.yaml'

# conf_file_path = '/etc/debderiver/debderiver.yaml'

main_conf = yaml.load(open(conf_file_path, 'r'))

# I'm not familiar with Yaml. When did we start to fill debderiver.yaml?
# I understand that it's a dict that could be shown in a readable form.
# 'os', 'description' and 'base_dir' are the keys that we're trying to access.
# But when did we fill them with values?

See examples/debderiver.yaml. yaml.load parses the file and maps it to appropriate Python structures.

2.
self._do(' '.join(('include' + ext, suite, p)))

# Could you explain the syntax of this join()?
# ext should be a list. How can we concatenate str and list?

Note the code above it: for f in filenames

It loops through the filenames and for each it takes the extension, and if it's some package file, then it executes include for the file. So if we want to import the Gnash repo [2] then for each file in pool/main/g/gnash it checks the extension and then executes e.g.

reprepro -Vb /data/gnewsense includedeb parkes /path/local/getgnashmirror/gnash_0.8.10-1~squeeze_i386.deb

3. I've also tried to write some tests. Here is the result. (Maybe we
shouldn't use IOError for this purpose. I'm not sure.)

if __name__ == "__main__":
+    # Check for debderiver.py in `/usr/local/bin'
+    if os.path.abspath(__file__) != '/usr/local/bin/debderiver.py':
+        raise IOError, 'Copy debderiver.py to `/usr/local/bin\''

It's not required to be in /usr/local/bin. I plan to make a proper debian package for it eventually, so it will install to /usr/bin.

+    # Check if `/etc/debderiver' already exists
+    # Create it if the dir doesn't exist
+    if not os.path.exists('/etc/debderiver'):
+        print 'Creating `/etc/debderiver\'...'
+        os.makedirs('/etc/debderiver')
+        print 'Done.'

This should also be handled by the installation procedure. I guess it's good to have this in for now. It should also check if there's a configuration file. If it's not there, it should suggest to copy the example file and edit it.

+    # Check for reprepro
+    if not os.path.exists('/usr/bin/reprepro'):
+        raise IOError, 'Missing dependency: install reprepro and try again.'
+
     CONF_DIR_PATH = '/etc/debderiver'

     conf = parse(CONF_DIR_PATH)

Nice.

4.
Can I write to http://bzr.savannah.gnu.org/lh/gnewsense/debderiver by myself?

If you show enough commitment and knowledge about the code.

I don't think Savannah supports personal (i.e. linked to user instead of 
project) branches, but maybe you have your own hosting or you could use 
Launchpad.
I'm going to run my own server soon. Could you tell me more about the
options I have?

You can make a Bazaar repository public with "bzr serve". I made the attached script for our bzr.gnewsense.org.

[1] http://docs.python.org/library/os.html#os.system
[2] http://www.getgnash.org/debs/debian/
#! /bin/sh
### BEGIN INIT INFO
# Provides:          bzrserve
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: Launch Bazaar server (read-only)
# Description:       Launch Bazaar server, a version control system, in 
read-only mode. Use bzr+ssh for write access.
### END INIT INFO

# Author: Sam Geeraerts <address@hidden>

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin
REPO_PATH=/srv/bzr/
DESC="Bazaar server"
NAME=bzr
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="serve --directory=$REPO_PATH"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
USER=bzr

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER \
                --exec $DAEMON --test >/dev/null || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER \
                --background --make-pidfile --exec $DAEMON -- $DAEMON_ARGS \
                || return 2
        # Add code here, if necessary, that waits for the process to be ready
        # to handle requests from services started subsequently which depend
        # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile 
$PIDFILE --name $NAME
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec 
$DAEMON
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
        #
        # If the daemon can reload its configuration without
        # restarting (for example, when it is sent a SIGHUP),
        # then implement that here.
        #
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name 
$NAME
        return 0
}

case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  status)
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
       ;;
  #reload|force-reload)
        #
        # If do_reload() is not implemented then leave this commented out
        # and leave 'force-reload' as an alias for 'restart'.
        #
        #log_daemon_msg "Reloading $DESC" "$NAME"
        #do_reload
        #log_end_msg $?
        #;;
  restart|force-reload)
        #
        # If the "reload" option is implemented then remove the
        # 'force-reload' alias
        #
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
        exit 3
        ;;
esac

:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]