Changeset - 1cb0a1f82fb4
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 12 years ago 2013-06-06 23:53:01
marcin@python-works.com
sync gist api and cli with rhodecode-pam.

This will is a part of API cleanup and rewrite
2 files changed with 11 insertions and 20 deletions:
0 comments (0 inline, 0 general)
rhodecode/bin/rhodecode_gist.py
Show inline comments
 
@@ -126,36 +126,37 @@ def _run(argv):
 
        raise Exception('Error: binary files upload is not possible')
 

	
 
    filename = os.path.basename(args.filename or filename)
 
    if gist_content:
 
        files = {
 
            filename: {
 
                'content': gist_content,
 
                'lexer': None
 
            }
 
        }
 

	
 
        margs = dict(
 
            gist_lifetime=args.lifetime,
 
            gist_description=args.description,
 
            lifetime=args.lifetime,
 
            description=args.description,
 
            gist_type='private' if args.private else 'public',
 
            files=files
 
        )
 

	
 
        json_data = api_call(apikey, host, 'create_gist', **margs)['result']
 
        if args.format == FORMAT_JSON:
 
            print json.dumps(json_data)
 
        elif args.format == FORMAT_PRETTY:
 
            print 'Created %s gist %s' % (json_data['gist_type'],
 
                                          json_data['gist_url'])
 
            print json_data
 
            print 'Created %s gist %s' % (json_data['gist']['type'],
 
                                          json_data['gist']['url'])
 
    return 0
 

	
 

	
 
def main(argv=None):
 
    """
 
    Main execution function for cli
 

	
 
    :param argv:
 
    """
 
    if argv is None:
 
        argv = sys.argv
 

	
rhodecode/controllers/api/api.py
Show inline comments
 
@@ -1060,51 +1060,41 @@ class ApiController(JSONRPCController):
 
                success=True
 
            )
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            raise JSONRPCError(
 
                'failed to edit permission for user group: `%s` in '
 
                'repo: `%s`' % (
 
                    users_group.users_group_name, repo.repo_name
 
                )
 
            )
 

	
 
    def create_gist(self, apiuser, files, owner=Optional(OAttr('apiuser')),
 
                    gist_type=Optional(Gist.GIST_PUBLIC),
 
                    gist_lifetime=Optional(-1),
 
                    gist_description=Optional('')):
 
                    gist_type=Optional(Gist.GIST_PUBLIC), lifetime=Optional(-1),
 
                    description=Optional('')):
 

	
 
        try:
 
            if isinstance(owner, Optional):
 
                owner = apiuser.user_id
 

	
 
            owner = get_user_or_error(owner)
 
            description = Optional.extract(gist_description)
 
            description = Optional.extract(description)
 
            gist_type = Optional.extract(gist_type)
 
            gist_lifetime = Optional.extract(gist_lifetime)
 
            lifetime = Optional.extract(lifetime)
 

	
 
            # files: {
 
            #    'filename': {'content':'...', 'lexer': null},
 
            #    'filename2': {'content':'...', 'lexer': null}
 
            #}
 
            gist = GistModel().create(description=description,
 
                                      owner=owner,
 
                                      gist_mapping=files,
 
                                      gist_type=gist_type,
 
                                      lifetime=gist_lifetime)
 
                                      lifetime=lifetime)
 
            Session().commit()
 
            return dict(
 
                msg='created new gist',
 
                gist_url=gist.gist_url(),
 
                gist_id=gist.gist_access_id,
 
                gist_type=gist.gist_type,
 
                files=files.keys()
 
                gist=gist.get_api_data()
 
            )
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            raise JSONRPCError('failed to create gist')
 

	
 
    def update_gist(self, apiuser):
 
        pass
 

	
 
    def delete_gist(self, apiuser):
 
        pass
0 comments (0 inline, 0 general)