##// END OF EJS Templates
artifacts: added CLI script for adding really big artifacts.
marcink -
r4005:804e6e03 default
parent child Browse files
Show More
@@ -0,0 +1,107 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2016-2019 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 import sys
22 import logging
23
24 import click
25
26 from rhodecode.lib.pyramid_utils import bootstrap
27 from rhodecode.model.db import Session, User, Repository
28 from rhodecode.model.user import UserModel
29 from rhodecode.apps.file_store import utils as store_utils
30
31 log = logging.getLogger(__name__)
32
33
34 @click.command()
35 @click.argument('ini_path', type=click.Path(exists=True))
36 @click.option(
37 '--filename',
38 required=True,
39 help='Filename for artifact.')
40 @click.option(
41 '--file-path',
42 required=True,
43 type=click.Path(exists=True, dir_okay=False, readable=True),
44 help='Path to a file to be added as artifact')
45 @click.option(
46 '--repo-id',
47 required=True,
48 type=int,
49 help='ID of repository to add this artifact to.')
50 @click.option(
51 '--user-id',
52 default=None,
53 type=int,
54 help='User ID for creator of artifact. '
55 'Default would be first super admin.')
56 @click.option(
57 '--description',
58 default=None,
59 type=str,
60 help='Add description to this artifact')
61 def main(ini_path, filename, file_path, repo_id, user_id, description):
62 return command(ini_path, filename, file_path, repo_id, user_id, description)
63
64
65 def command(ini_path, filename, file_path, repo_id, user_id, description):
66 with bootstrap(ini_path, env={'RC_CMD_SETUP_RC': '1'}) as env:
67 try:
68 from rc_ee.api.views.store_api import _store_file
69 except ImportError:
70 click.secho('ERROR: Unable to import store_api. '
71 'store_api is only available in EE edition of RhodeCode',
72 fg='red')
73 sys.exit(-1)
74
75 request = env['request']
76
77 repo = Repository.get(repo_id)
78 if not repo:
79 click.secho('ERROR: Unable to find repository with id `{}`'.format(repo_id),
80 fg='red')
81 sys.exit(-1)
82
83 # if we don't give user, or it's "DEFAULT" user we pick super-admin
84 if user_id is not None or user_id == 1:
85 db_user = User.get(user_id)
86 else:
87 db_user = User.get_first_super_admin()
88
89 if not db_user:
90 click.secho('ERROR: Unable to find user with id/username `{}`'.format(user_id),
91 fg='red')
92 sys.exit(-1)
93
94 auth_user = db_user.AuthUser(ip_addr='127.0.0.1')
95
96 storage = store_utils.get_file_storage(request.registry.settings)
97
98 with open(file_path, 'rb') as f:
99 click.secho('Adding new artifact from path: `{}`'.format(file_path),
100 fg='green')
101
102 file_data = _store_file(
103 storage, auth_user, filename, content=None, check_acl=True,
104 file_obj=f, description=description,
105 scope_repo_id=repo.repo_id)
106 click.secho('File Data: {}'.format(file_data),
107 fg='green')
@@ -1,179 +1,180 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2019 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 # Import early to make sure things are patched up properly
22 22 from setuptools import setup, find_packages
23 23
24 24 import os
25 25 import sys
26 26 import pkgutil
27 27 import platform
28 28 import codecs
29 29
30 30 try: # for pip >= 10
31 31 from pip._internal.req import parse_requirements
32 32 except ImportError: # for pip <= 9.0.3
33 33 from pip.req import parse_requirements
34 34
35 35 try: # for pip >= 10
36 36 from pip._internal.download import PipSession
37 37 except ImportError: # for pip <= 9.0.3
38 38 from pip.download import PipSession
39 39
40 40
41 41 if sys.version_info < (2, 7):
42 42 raise Exception('RhodeCode requires Python 2.7 or later')
43 43
44 44 here = os.path.abspath(os.path.dirname(__file__))
45 45
46 46 # defines current platform
47 47 __platform__ = platform.system()
48 48 __license__ = 'AGPLv3, and Commercial License'
49 49 __author__ = 'RhodeCode GmbH'
50 50 __url__ = 'https://code.rhodecode.com'
51 51 is_windows = __platform__ in ('Windows',)
52 52
53 53
54 54 def _get_requirements(req_filename, exclude=None, extras=None):
55 55 extras = extras or []
56 56 exclude = exclude or []
57 57
58 58 try:
59 59 parsed = parse_requirements(
60 60 os.path.join(here, req_filename), session=PipSession())
61 61 except TypeError:
62 62 # try pip < 6.0.0, that doesn't support session
63 63 parsed = parse_requirements(os.path.join(here, req_filename))
64 64
65 65 requirements = []
66 66 for ir in parsed:
67 67 if ir.req and ir.name not in exclude:
68 68 requirements.append(str(ir.req))
69 69 return requirements + extras
70 70
71 71
72 72 # requirements extract
73 73 setup_requirements = ['PasteScript', 'pytest-runner']
74 74 install_requirements = _get_requirements(
75 75 'requirements.txt', exclude=['setuptools', 'entrypoints'])
76 76 test_requirements = _get_requirements(
77 77 'requirements_test.txt', extras=['configobj'])
78 78
79 79
80 80 def get_version():
81 81 version = pkgutil.get_data('rhodecode', 'VERSION')
82 82 return version.strip()
83 83
84 84
85 85 # additional files that goes into package itself
86 86 package_data = {
87 87 '': ['*.txt', '*.rst'],
88 88 'configs': ['*.ini'],
89 89 'rhodecode': ['VERSION', 'i18n/*/LC_MESSAGES/*.mo', ],
90 90 }
91 91
92 92 description = 'Source Code Management Platform'
93 93 keywords = ' '.join([
94 94 'rhodecode', 'mercurial', 'git', 'svn',
95 95 'code review',
96 96 'repo groups', 'ldap', 'repository management', 'hgweb',
97 97 'hgwebdir', 'gitweb', 'serving hgweb',
98 98 ])
99 99
100 100
101 101 # README/DESCRIPTION generation
102 102 readme_file = 'README.rst'
103 103 changelog_file = 'CHANGES.rst'
104 104 try:
105 105 long_description = codecs.open(readme_file).read() + '\n\n' + \
106 106 codecs.open(changelog_file).read()
107 107 except IOError as err:
108 108 sys.stderr.write(
109 109 "[WARNING] Cannot find file specified as long_description (%s)\n "
110 110 "or changelog (%s) skipping that file" % (readme_file, changelog_file))
111 111 long_description = description
112 112
113 113
114 114 setup(
115 115 name='rhodecode-enterprise-ce',
116 116 version=get_version(),
117 117 description=description,
118 118 long_description=long_description,
119 119 keywords=keywords,
120 120 license=__license__,
121 121 author=__author__,
122 122 author_email='support@rhodecode.com',
123 123 url=__url__,
124 124 setup_requires=setup_requirements,
125 125 install_requires=install_requirements,
126 126 tests_require=test_requirements,
127 127 zip_safe=False,
128 128 packages=find_packages(exclude=["docs", "tests*"]),
129 129 package_data=package_data,
130 130 include_package_data=True,
131 131 classifiers=[
132 132 'Development Status :: 6 - Mature',
133 133 'Environment :: Web Environment',
134 134 'Intended Audience :: Developers',
135 135 'Operating System :: OS Independent',
136 136 'Topic :: Software Development :: Version Control',
137 137 'License :: OSI Approved :: Affero GNU General Public License v3 or later (AGPLv3+)',
138 138 'Programming Language :: Python :: 2.7',
139 139 ],
140 140 message_extractors={
141 141 'rhodecode': [
142 142 ('**.py', 'python', None),
143 143 ('**.js', 'javascript', None),
144 144 ('templates/**.mako', 'mako', {'input_encoding': 'utf-8'}),
145 145 ('templates/**.html', 'mako', {'input_encoding': 'utf-8'}),
146 146 ('public/**', 'ignore', None),
147 147 ]
148 148 },
149 149 paster_plugins=['PasteScript'],
150 150 entry_points={
151 151 'paste.app_factory': [
152 152 'main=rhodecode.config.middleware:make_pyramid_app',
153 153 ],
154 154 'paste.global_paster_command': [
155 155 'ishell=rhodecode.lib.paster_commands.ishell:Command',
156 156 'upgrade-db=rhodecode.lib.paster_commands.upgrade_db:UpgradeDb',
157 157
158 158 'setup-rhodecode=rhodecode.lib.paster_commands.deprecated.setup_rhodecode:Command',
159 159 'celeryd=rhodecode.lib.paster_commands.deprecated.celeryd:Command',
160 160 ],
161 161 'pyramid.pshell_runner': [
162 162 'ipython = rhodecode.lib.pyramid_shell:ipython_shell_runner',
163 163 ],
164 164 'pytest11': [
165 165 'pylons=rhodecode.tests.pylons_plugin',
166 166 'enterprise=rhodecode.tests.plugin',
167 167 ],
168 168 'console_scripts': [
169 169 'rc-setup-app=rhodecode.lib.rc_commands.setup_rc:main',
170 170 'rc-upgrade-db=rhodecode.lib.rc_commands.upgrade_db:main',
171 171 'rc-ishell=rhodecode.lib.rc_commands.ishell:main',
172 'rc-add-artifact=rhodecode.lib.rc_commands.add_artifact:main',
172 173 'rc-ssh-wrapper=rhodecode.apps.ssh_support.lib.ssh_wrapper:main',
173 174 ],
174 175 'beaker.backends': [
175 176 'memorylru_base=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerBase',
176 177 'memorylru_debug=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerDebug'
177 178 ]
178 179 },
179 180 )
General Comments 0
You need to be logged in to leave comments. Login now