-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccr-tools
More file actions
executable file
·153 lines (122 loc) · 6.04 KB
/
Copy pathccr-tools
File metadata and controls
executable file
·153 lines (122 loc) · 6.04 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/python3
version = '0.0.1'
import sys
import argparse
import getpass
import logging
import os
import json
import ccr
import ccrauth
logging.disable(logging.CRITICAL)
CCRTOOLS_PATH = os.path.expanduser('~') + '/.config/ccr-tools/'
CCRTOOLS_CONFIG_FILE = CCRTOOLS_PATH + 'ccr-tools.conf'
CCR_DB = CCRTOOLS_PATH + 'ccrauth.db'
CCRAUTH_FILE = CCRTOOLS_PATH + 'ccrauth.txt'
def parse_args():
parser = argparse.ArgumentParser(prog="ccr-tools",
description="A tool to interact with the Chakra Community Repository.",
#usage="%(prog)s [options] <pkgname1> <pkgname2> ...",
epilog=" examples:\tVote for packages 'shake' and 'bfilter' :\n"
"\t\t ccr-tools --vote shake bfilter\n\n"
"\t\tAdopt package 'shake' and set the notify flag :\n"
"\t\t ccr-tools -an shake\n\n"
"\t\tStore login information :\n"
"\t\t ccr-tools --login-info\n"
"\t\t(username, password and storage method will be asked)\n"
"\t\tTo create a new account just go to:\n"
"\t\t" + ccr.CCR_BASE + "account.php",
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--version', action='version',
version="%(prog)s " + version + " (http://ccr-tools.github.io)")
parser.add_argument('--login-info', action='store_true',
help="store login information in KWallet, a database or a file")
parser.add_argument('--remove-login-info', action='store_true', help="remove login information")
parser.add_argument('-l', '--list-categories', action='store_true', help="list all valid categories")
parser.add_argument('-S', '--status', action='store_true', help="list the status of owned packages")
parser.add_argument('-c', '--check-vote', action='store_true', help="check for voted packages")
parser.add_argument('-v', '--vote', action='store_true', help="vote for packages")
parser.add_argument('-V', '--unvote', action='store_true', help="unvote packages")
parser.add_argument('-f', '--flag', action='store_true', help="flag packages as out of date")
parser.add_argument('-F', '--unflag', action='store_true', help="unflag packages as out of date")
parser.add_argument('-n', '--notify', action='store_true', help="set the notify flag on packages")
parser.add_argument('-N', '--unnotify', action='store_true', help="unset the notify flag on packages")
parser.add_argument('-a', '--adopt', action='store_true', help="adopt orphaned packages")
parser.add_argument('-D', '--disown', action='store_true', help="disown packages")
parser.add_argument('-s', '--submit', action='store_true', help="submit new packages")
parser.add_argument('-C', '--setcategory', action='store_true', help="set the category for new packages")
parser.add_argument('-d', '--delete', action='store_true', help="delete packages")
#parser.add_argument('-m', '--maintainer', action='store_true', help="list all packages by maintainer")
parser.add_argument('pkgs', metavar='<pkgname>', nargs='*')
return parser.parse_args()
def config():
if not os.access(CCRTOOLS_PATH, os.F_OK):
os.mkdir(CCRTOOLS_PATH)
if os.access(CCRTOOLS_CONFIG_FILE, os.F_OK):
with open(CCRTOOLS_CONFIG_FILE) as file:
data = json.load(file)
return data['storage_method']
else:
return None
def login_info():
config = {'storage_method': None}
auth = None
print("Enter login information")
username = input("Username: ")
password = getpass.getpass("Password: ")
method = input("Store login information? (k)wallet / (d)atabase / (f)ile / (n)o")
if method != 'n':
if method == 'k':
auth = ccrauth.AuthKWallet()
elif method == 'd':
auth = ccrauth.AuthDB()
auth.CCR_DB = CCR_DB
elif method == 'f':
auth = ccrauth.AuthFile()
auth.CCRAUTH_FILE = CCRAUTH_FILE
auth.store_auth_info(username, password)
config['storage_method'] = method.lower()
with open(CCRTOOLS_CONFIG_FILE, 'w') as file:
json.dump(config, file)
return username, password
def login():
auth = None
username = None
password = None
storage_method = config()
if storage_method is None:
username, password = login_info()
elif storage_method == 'k':
auth = ccrauth.AuthKWallet()
elif storage_method == 'd':
auth = ccrauth.AuthDB()
elif storage_method == 'f':
auth = ccrauth.AuthFile()
if auth is not None:
username = auth.username
password = auth.password
return ccr.Session(username, password)
if __name__ == '__main__':
modname = sys.modules[globals()['__name__']]
args = vars(parse_args())
pkgargs = args['pkgs']
nologin_options = ['login_info', 'delete_login_info', 'list_categories', 'status']
for option in args.keys():
if args[option] is True:
# options that don't need to login to CCR
if option in nologin_options:
getattr(modname, option)()
exit(0)
if not args['pkgs']:
print('--' + option + " option needs at least one package name.")
exit(1)
# options that need to login to CCR
session = login()
for pkg in pkgargs:
try:
if getattr(session, option)(pkg) is not None:
print(option + '-TRUE OR FALSE') # True or False returned by ccr.Session method
print(option + '-OK') # no error
except None:
print(option + '-ERROR') # error occured
continue