This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
cmdline.py
87 lines (69 loc) · 2.25 KB
/
cmdline.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""
Commandline handling
Note that argparse is not part of Python 2.6, so we cannot rely on it here.
"""
#*****************************************************************************
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
import os
import sys
import logging
log = logging.getLogger()
class CmdlineSubcommands(object):
def __init__(self, argv=None):
if argv is None:
argv = sys.argv
if len(argv) == 1:
self.print_help()
sys.exit(0)
self.subcommand = argv[1]
self.extra_args = argv[2:]
def print_help(self):
from textwrap import dedent
print(dedent(self.__doc__).lstrip())
def run(self):
try:
method = getattr(self, 'run_{0}'.format(self.subcommand))
except AttributeError:
log.error('unknown subcommand: {0}'.format(self.subcommand))
sys.exit(1)
try:
method(*self.extra_args)
except TypeError as err:
log.error('invalid arguments to the {0} subcommand: {1}'
.format(self.subcommand, self.extra_args))
sys.exit(1)
class SagePkgApplication(CmdlineSubcommands):
"""
sage-pkg
--------
The package script is used to manage third-party tarballs.
"""
def run_config(self):
"""
Print the configuration
"""
from sage_bootstrap.config import Configuration
print(Configuration())
def run_list(self):
"""
Print a list of all available packages
"""
pass
def run_name(self, tarball_filename):
"""
Find the package name given a tarball filename
"""
pass
def run_tarball(self, package_name):
"""
Find the tarball filename given a package name
"""
pass