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