/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/command_init.py

  • Committer: Tim Marston
  • Date: 2013-12-08 19:28:11 UTC
  • Revision ID: tim@ed.am-20131208192811-r20qj7cgmn4duw11
initial commit; basic app startup and initial command-line processing

Show diffs side-by-side

added added

removed removed

 
1
# command_init.py
 
2
#
 
3
# Copyright (C) 2013 Tim Marston <tim@edm.am>
 
4
#
 
5
# This file is part of stdhome (hereafter referred to as "this program").
 
6
# See http://ed.am/dev/stdhome for more information.
 
7
#
 
8
# This program is free software: you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation, either version 3 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
 
 
22
import sys, os
 
23
import getopt
 
24
 
 
25
 
 
26
class CommandInit:
 
27
 
 
28
        def print_help( self ):
 
29
                print "Usage: " + self.program + " init [URL] [--repo=REPO]"
 
30
                print
 
31
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
 
32
                print "Initialise a local repository."
 
33
                print
 
34
                print "If an URL is given, the local reposity is a checkout of it (i.e., you can"
 
35
                print "receive updates from it and changes you commit will be sent to it).  The URL"
 
36
                print "can take the form of a simple hostname, such as \"example.com\", or it can be a"
 
37
                print "fully-qualified bazaar URL.  (Actually, in the first case, where it is a simple"
 
38
                print "hostname, it is internally expanded to scp://HOSTNAME/~/.stdhome/REPO)."
 
39
                print
 
40
                print "Options:"
 
41
                print "     --repo     select the repo to check-out or create (defaults to 'home')"
 
42
                print "     --help     display help and exit"
 
43
                exit( 0 )
 
44
 
 
45
 
 
46
        def run( self, stdhome ):
 
47
                # parse command line
 
48
                try:
 
49
                        opts, args = getopt.gnu_getopt(
 
50
                                sys.argv[ 1: ], "",
 
51
                                [ "repo:", "help" ] )
 
52
                except getopt.GetoptError as e:
 
53
                        stdhome.print_usage( e )
 
54
                for opt, optargs in opts:
 
55
                        if opt == "--help":
 
56
                                self.print_help()
 
57
                        elif aopt == "--repo":
 
58
                                self.repo = optarg
 
59
 
 
60
                print "init"