snapshot 2020-12-20 18:21:14.281876
This commit is contained in:
		
							parent
							
								
									2859c7c2c7
								
							
						
					
					
						commit
						188468e3bc
					
				@ -2,11 +2,14 @@
 | 
			
		||||
Git snapshotting tool
 | 
			
		||||
"""
 | 
			
		||||
from .lethe import (
 | 
			
		||||
    main, snap, snap_ref, snap_tree, find_merge_base, deref_symref,
 | 
			
		||||
    snap, snap_ref, snap_tree, find_merge_base, deref_symref,
 | 
			
		||||
    update_ref, commit_tree, get_tree, get_commit, get_obj,
 | 
			
		||||
    shorten_hash, get_root, get_latest_commit,
 | 
			
		||||
    push_ref, fetch_ref,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
from .endpoints import main
 | 
			
		||||
from .VERSION import __version__
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__author__ = 'Jan Petykeiwicz'
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
from .lethe import main
 | 
			
		||||
from .endpoints import main
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    main()
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										47
									
								
								lethe/endpoints.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								lethe/endpoints.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,47 @@
 | 
			
		||||
import argparse
 | 
			
		||||
 | 
			
		||||
from .lethe import snap, push_ref, fetch_ref
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main() -> int:
 | 
			
		||||
    parser = argparse.ArgumentParser()
 | 
			
		||||
    parser.add_argument('--parent', '-p', action='append', default=['HEAD'])
 | 
			
		||||
    parser.add_argument('--target', '-t', action='append')
 | 
			
		||||
    parser.add_argument('--message', '-m')
 | 
			
		||||
    parser.add_argument('--repo', '-r')
 | 
			
		||||
 | 
			
		||||
    args = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
    print(snap(parent_refs=args.parent,
 | 
			
		||||
               target_refs=args.target,
 | 
			
		||||
               message=args.message,
 | 
			
		||||
               cwd=args.repo))
 | 
			
		||||
    return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def push() -> int:
 | 
			
		||||
    parser = argparse.ArgumentParser()
 | 
			
		||||
    parser.add_argument('--remote', '-s', default='origin')
 | 
			
		||||
    parser.add_argument('--target', '-t', default='refs/lethe/HEAD')
 | 
			
		||||
    parser.add_argument('--repo', '-r')
 | 
			
		||||
 | 
			
		||||
    args = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
    print(push_ref(remote=args.remote,
 | 
			
		||||
                   target_ref=args.target,
 | 
			
		||||
                   cwd=args.repo))
 | 
			
		||||
    return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def fetch() -> int:
 | 
			
		||||
    parser = argparse.ArgumentParser()
 | 
			
		||||
    parser.add_argument('--remote', '-s', default='origin')
 | 
			
		||||
    parser.add_argument('--target', '-t', default='refs/lethe/HEAD')
 | 
			
		||||
    parser.add_argument('--repo', '-r')
 | 
			
		||||
 | 
			
		||||
    args = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
    print(fetch_ref(remote=args.remote,
 | 
			
		||||
                    remote_ref=args.target,
 | 
			
		||||
                    cwd=args.repo))
 | 
			
		||||
    return 0
 | 
			
		||||
@ -110,6 +110,34 @@ def update_ref(target_ref: str,
 | 
			
		||||
    return result_ref
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def push_ref(remote: str = 'origin',
 | 
			
		||||
             target_ref: str = 'refs/lethe/HEAD',
 | 
			
		||||
             remote_ref: Optional[str] = None,
 | 
			
		||||
             cwd: Optional[str] = None,
 | 
			
		||||
             ) -> str:
 | 
			
		||||
    """
 | 
			
		||||
    Push `target_ref` to `remote` as `remote_ref`.
 | 
			
		||||
    By default, `remote_ref` will be the same as `target_ref`.
 | 
			
		||||
    """
 | 
			
		||||
    if remote_ref is None:
 | 
			
		||||
        remote_ref = target_ref
 | 
			
		||||
    return _run(['git', 'push', remote, target_ref + ':' + remote_ref], cwd=cwd)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def fetch_ref(remote: str = 'origin',
 | 
			
		||||
              remote_ref: str = 'refs/lethe/HEAD',
 | 
			
		||||
              target_ref: Optional[str] = None,
 | 
			
		||||
              cwd: Optional[str] = None,
 | 
			
		||||
              ) -> str:
 | 
			
		||||
    """
 | 
			
		||||
    Fetch `remote_ref` from `remote` as `target_ref`.
 | 
			
		||||
    By default, `target_ref` will be the same as `remote_ref`.
 | 
			
		||||
    """
 | 
			
		||||
    if target_ref is None:
 | 
			
		||||
        target_ref = remote_ref
 | 
			
		||||
    return _run(['git', 'fetch', remote, remote_ref + ':' + target_ref], cwd=cwd)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def deref_symref(ref: str, cwd: Optional[str] = None) -> str:
 | 
			
		||||
    """
 | 
			
		||||
    Dereference a symbolic ref
 | 
			
		||||
@ -214,24 +242,3 @@ def snap(parent_refs: Optional[List[str]] = None,
 | 
			
		||||
 | 
			
		||||
    commit = snap_ref(parent_refs, target_refs, message=message, cwd=cwd)
 | 
			
		||||
    return commit
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main() -> int:
 | 
			
		||||
    parser = argparse.ArgumentParser()
 | 
			
		||||
    parser.add_argument('--parent', '-p', action='append', default=['HEAD'])
 | 
			
		||||
    parser.add_argument('--target', '-t', action='append')
 | 
			
		||||
    parser.add_argument('--message', '-m')
 | 
			
		||||
    parser.add_argument('--repo', '-r')
 | 
			
		||||
 | 
			
		||||
    args = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
    print(snap(parent_refs=args.parent,
 | 
			
		||||
               target_refs=args.target,
 | 
			
		||||
               message=args.message,
 | 
			
		||||
               cwd=args.repo))
 | 
			
		||||
    return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    main()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								setup.py
									
									
									
									
									
								
							@ -9,7 +9,6 @@ with open('README.md', 'rt') as f:
 | 
			
		||||
with open('lethe/VERSION.py', 'rt') as f:
 | 
			
		||||
    version = f.readlines()[2].strip()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
setup(name='lethe',
 | 
			
		||||
      version=version,
 | 
			
		||||
      description='Git-based snapshotting',
 | 
			
		||||
@ -24,7 +23,9 @@ setup(name='lethe',
 | 
			
		||||
      },
 | 
			
		||||
      entry_points={
 | 
			
		||||
          'console_scripts': [
 | 
			
		||||
              'lethe=lethe:main',
 | 
			
		||||
              'lethe=lethe:endpoints.main',
 | 
			
		||||
              'lethe-push=lethe:endpoints.push',
 | 
			
		||||
              'lethe-fetch=lethe:endpoints.fetch',
 | 
			
		||||
          ],
 | 
			
		||||
      },
 | 
			
		||||
      install_requires=[
 | 
			
		||||
@ -42,6 +43,7 @@ setup(name='lethe',
 | 
			
		||||
            'traceability',
 | 
			
		||||
      ],
 | 
			
		||||
      classifiers=[
 | 
			
		||||
            'Programming Language :: Python',
 | 
			
		||||
            'Programming Language :: Python :: 3',
 | 
			
		||||
            'Development Status :: 4 - Beta',
 | 
			
		||||
            'Environment :: Other Environment',
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user