This repository was archived by the owner on Dec 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopenstore-cli
More file actions
executable file
·146 lines (117 loc) · 6.15 KB
/
Copy pathopenstore-cli
File metadata and controls
executable file
·146 lines (117 loc) · 6.15 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
#!/usr/bin/python3
import sys
import os
import shutil
import argparse
import openstorecli
from os.path import isfile
import urllib, requests
class MyParser(argparse.ArgumentParser):
def error(self, message):
self.print_help()
sys.exit(2)
parser = MyParser(description="This is the CLI tool for the OpenStore app store service. Manage or search apps for your Ubuntu Touch device.",
usage="'openstore-cli <command>'",
epilog="Run 'openstore-cli <command> help' to see the options available for each command.")
subparsers = parser.add_subparsers(dest='cmd', title="Commands")
# Argument parser: upload command
parser_upload = subparsers.add_parser('upload', help="Push a new package to the OpenStore server, as update or new submission.")
parser_upload.add_argument('file_path', type=str, help="The path of the .click package")
parser_upload.add_argument('-y', '--yes', dest='force_yes', action='store_true', help="Automatic yes to prompts. Assume \"yes\" as answer to all prompts and run non-interactively.")
# Argument parser: update-info command
parser_update_info = subparsers.add_parser('update-info', help="Update remote informations of a package on the OpenStore server")
parser_update_info.add_argument('app_id', type=str, help="The appId of the .click package")
parser_update_info.add_argument('-c', '--changelog', dest='changelog', type=str, help="Update changelog field on server")
parser_update_info.add_argument('-d', '--description', dest='description', type=str, help="Update description field on server")
parser_update_info.add_argument('-g', '--category', dest='category', type=str, help="Update category field on server")
parser_update_info.add_argument('-l', '--license', dest='license', type=str, help="Update license field on server")
parser_update_info.add_argument('-p', '--publish', dest='publish', action='store_true', help="Publish the package")
parser_update_info.add_argument('-s', '--source', dest='source', type=str, help="Update source code url field on server")
parser_update_info.add_argument('-t', '--tagline', dest='tagline', type=str, help="Update tagline field on server")
parser_update_info.add_argument('-u', '--unpublish', dest='unpublish', action='store_true', help="Unpublish the package")
parser_update_info.add_argument('-y', '--yes', dest='force_yes', action='store_true', help="Automatic yes to prompts. Assume \"yes\" as answer to all prompts and run non-interactively.")
# Argument parser: search command
parser_search = subparsers.add_parser('search', help="Search an application available on the store (by its id, name, keyword, or description")
parser_search.add_argument('query', type=str, help="The query of the search")
# Argument parser: info command
parser_info = subparsers.add_parser('info', help="Display information available for a single application")
parser_info.add_argument('app_id', type=str, help="The appId as it appears inside the manifest of the package")
parser_info.add_argument('-A', '--with-auth', dest='with_auth', action='store_true', help='Access with your credentials. It allows to display info of not published apps. You must be the owner of the package.')
# Argument parser: add-api-key command
parser_add_api = subparsers.add_parser('add-api-key', help="Add your API key. Required for managing apps. \n NOTE: You can also provide your API key by exporting the 'OPENSTORE_API_KEY' env.")
parser_add_api.add_argument('api_key', type=str, help="Your API key")
# Argument parser: show-api-key command
parser_show_api = subparsers.add_parser('show-api-key', help="Show the API key available for this tool.")
args = parser.parse_args()
uApp = openstorecli.repo()
if args.cmd == "upload":
if not uApp.hasApi():
print ("You have not provided a API key")
print ("Use 'openstore-cli add-api-key [key]' to set the api key")
sys.exit()
uApp.upload(args.file_path, args.force_yes)
# Should be okay
elif args.cmd == "update-info":
if not uApp.hasApi():
print ("You have not provided a API key")
print ("Use 'openstore-cli add-api-key [key]' to set the api key")
sys.exit()
if args.license: uApp.update["license"] = args.license
if args.tagline: uApp.update["tagline"] = args.tagline
if args.source: uApp.update["source"] = args.source
if args.description: uApp.update["description"] = args.description
if args.category: uApp.update["category"] = args.category
if args.changelog: uApp.update["changelog"] = args.changelog
if args.publish and args.unpublish:
print ("You should provide only one choice between 'publish' and 'unpublish' option")
sys.exit()
if args.publish: uApp.update["published"] = 'true'
if args.unpublish: uApp.update["published"] = 'false'
uApp.update_info(args.app_id, args.force_yes)
elif args.cmd == "add-api-key":
uApp.api = args.api_key
uApp.saveConfig()
print ("API key successfully saved")
elif args.cmd == "show-api-key":
uApp.loadConfig()
if uApp.hasApi():
print ("Your API key is", uApp.api)
else:
print ("API key not defined.")
elif args.cmd == "search":
res = uApp.search(args.query)
notFound=True
idx=1
for i in res["data"]:
notFound=False
print("=== Result no.", idx, "===")
if not i["name"] == "": print ("Name: " + i["name"])
if not i["author"] == "": print ("Author: " + i["author"])
if not i["id"] == "": print ("Id: " + i["id"])
print("\n")
idx = idx + 1
if (notFound): print ("Cannot find any app for the requested query.")
elif args.cmd == "info":
res = {}
if args.with_auth:
if not uApp.hasApi():
print ("You have not provided a API key")
print ("Use 'openstore-cli add-api-key [key]' to set the api key")
sys.exit()
else:
res = uApp.infoWithAuth(args.app_id)
else:
res = uApp.info(args.app_id)
notFound=True
i = res["data"]
if args.app_id == i["id"]:
notFound=False
if not i["name"] == "": print ("Name: " + i["name"])
if not i["description"] == "": print ("Description: " + i["description"])
if not i["tagline"] == "": print ("Tagline: " + i["tagline"])
if not i["license"] == "": print ("License: " + i["license"])
if not i["author"] == "": print ("Author: " + i["author"])
if not i["category"] == "": print ("Category: " + i["category"])
if (notFound): print ("Cannot find app with a id: " + args.app_id)
else:
parser.print_help()