File: repository.py

package info (click to toggle)
subuser 0.6.2-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,216 kB
  • sloc: python: 5,204; sh: 380; makefile: 73; javascript: 43
file content (58 lines) | stat: -rwxr-xr-x 1,877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#external imports
import sys
import optparse
#internal imports
from subuserlib.classes.user import LockedUser
import subuserlib.resolve
import subuserlib.repository
import subuserlib.commandLineArguments
import subuserlib.profile

def parseCliArgs(sysargs):
  usage = "usage: subuser repository [options] [add|remove] NAME <URL>"
  description = """Add or remove a new named repository.

- EXAMPLE
    Add a new repository named foo with the URI https://www.example.com/repo.git.

    $ subuser repository add foo https://www.example.com/repo.git
    $ #You can also add a local repository:
    $ subuser repository add local-foo file:///home/timothy/my-local-repo/

- EXAMPLE
    Remove the repository named foo.

    $subuser repository remove foo

  """
  parser=optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription())
  return parser.parse_args(args=sysargs)

@subuserlib.profile.do_cprofile
def runCommand(sysargs):
  """
  Manage named subuser repositories.
  """
  options,args = parseCliArgs(sysargs)
  lockedUser = LockedUser()
  with lockedUser as user:
    user.registry.commit_message = " ".join(["subuser","repository"]+sysargs)
    try:
      action = args[0]
    except IndexError:
      sys.exit("Use subuser repository --help for help.")
    if action == "add":
      if not len(args) == 3:
        sys.exit("Use subuser repository --help for help.")
      name = args[1]
      url = args[2]
      subuserlib.repository.add(user,name,url)
    elif action == "remove":
      if not len(args) == 2:
        sys.exit("Use subuser repository --help for help.")
      name = args[1]
      subuserlib.repository.remove(user,name)
    else:
       sys.exit("Action "+args[0]+" not supported. Please see:\n subuser repository --help")