Skip to content

Commit

Permalink
refactor main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
chidimo committed Dec 3, 2018
1 parent 0afae41 commit e395e08
Show file tree
Hide file tree
Showing 20 changed files with 365 additions and 369 deletions.
14 changes: 14 additions & 0 deletions Pipfile
@@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
coverage = "==4.5.1"
"send2trash" = "==1.5.0"

[dev-packages]
twine = "*"

[requires]
python_version = "3.6"
176 changes: 176 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 53 additions & 76 deletions README.md
Expand Up @@ -24,139 +24,116 @@ Just unzip it and place it somewhere on your disk. Later (during initialization)

## Installation

```python

`pip install https://codeload.github.com/immensity/python-git/zip/master`

`pip install python-git --upgrade`
```

## Usage
## Initial setup

Upon successful installation, the below command should return a blank screen
1. To setup, you need to look for where `pygit` is installed in your system. If you're using anaconda it would likely be in `C:\ProgramData\Anaconda3\Lib\site-packages\pygit`. then issue the command

import pygit
`$ python <full_installation_path>\main.py`.

To use `python-git`, you have to tell it exactly two things, depending on your system setup.
For finding files in your system I recommend [everything](https://www.voidtools.com/)

1. The location of your `git` repositories. You may do this by passing it a list of strings on the command line.
Each string represents a full path name to single directory. You may also just provide a single directory which holds
multiple git repositories and `pygit` will grab all the repositories for your.
## Usage

1. The location of a `git` executable. This only applies if `git` is not accessible from your system `cmd`. That is, `git` is
2. not in your system path. More on this below.
1. Activate python environment on command line.

If you have a master directory that holds multiple `git` repositories, `pygit` can also take the full path name of this master directory
and then index the git repositories it finds there. It won't index those directories that are not git repos.
`import pygit # should return nothing if all goes well`

It is also possible to tell `pygit` not to index certain directories by specifying the starting string of the directory name. This is referred
to s a `rule`. Directories matching such rules will not be touched.
1. Now you need to specify exactly two things:

To initialize `pygit`, run
1. where your git repos are
1. where your `git-cmd.exe` is located.

pygit.initialize()
1. The location of your `git` repositories. You may do this by passing it a list of strings on the command line. Each string represents a full path name to single directory. You may also just provide a single directory which holds multiple git repositories and `pygit` will grab all the repositories for your. If you have a master directory that holds multiple `git` repositories, `pygit` can also take the full path name of this master directory and then index the git repositories it finds there. It won't index those directories that are not git repos. It is also possible to tell `pygit` not to index certain directories by specifying the starting string of the directory name. This is referred to as a `rule`. Directories matching such rules will not be touched.
1. The location of a `git-cmd.exe` executable. This only applies if `git` is not accessible from your system `cmd`. That is, `git` is not in your system path. More on this below.

In case things change (perhaps you moved folders around) and you want to reset your folders,
just run the `set_all()` command again
just redo the initialization step

To see all available repositories run

To see all available repositories run ::
`pygit.show_repos()`

pygit.show_repos()
This command shows a list of all available repositories in the format

This command shows a list of all available repositories in the format ::
`repository_id: repository_name: repository_directory_path`

repository_id: repository_name: repository_directory_path
To load a particular repository use

To load a particular repository use ::
`pygit.load(repo_id_or_name)`

pygit.load(repo_id_or_name)
where `repo_id` is a string-valued id assigned to that particular repo. The first value in the `show_repos` command's output.

where **repo_id** is a string-valued id assigned to that particular repo. The first value in the `show_repos` command's output.
The `load\(\)` command returns a `Commands` object for that repo, which provides a gateway for issuing git commands on the repository

Operations that can be performed on `Commands` object are shown below.

The **load\(\)** command returns a `Commands` object for that repo, which provides a gateway for issuing git commands on the repository

Operations that can be performed on `Commands` object are shown below. ::

Commands().fetch() # perform fetch.
```python

Commands().fetch() # perform fetch
Commands().status() # see status

Commands().add_all() # stage all changes for commit

Commands().commit(message='minor changes') # commit changes. Press enter to accept default message

Commands().push() # perform push action

Commands().pull() # perform pull request

Commands().add_commit() # add and commit at once


```

### Batch Operations

Pygit provides some functions for performing batch operations on your repositories. ::
Pygit provides some functions for performing batch operations on your repositories.

pygit.load_multiple(*args)
`pygit.load_multiple(*args)`

loads a set of repositories. You could decide to only load only 2 of 10 repositories. Perhaps you need to perform similar actions
on those two alone. As an example

pygit.load_set("2", "5")
`pygit.load_set("2", "5")`

returns a `generator` of `Commands` objects for repositories 2 and 5. Afterwards you can use a :py:func:`for` loop to iterate over the repos
like below
returns a `generator` of `Commands` objects for repositories 2 and 5. Afterwards you can iterate over the repos like below

```python
for each in pygit.load_set("2", "5"):
each.add_commit()
```

pygit.all_status()
`pygit.all_status()`

performs a **status** command on all your repositories. The result is written to a text file. The text file opens automatically.
performs a `status` command on all your repositories. The result is written to a text file. The text file opens automatically.
The name of the file shows the date and time of the status request. All batch status request is written to its a separate file.
Call it a snapshot of your repo status if you will
Those items which are out of sync with their remote counterpart (by being ahead or being behind) are also highlighted as needing attention. ::
Those items which are out of sync with their remote counterpart (by being ahead or being behind) are also highlighted as needing attention.

pygit.pull_all()
`pygit.pull_all()`

performs a `pull` request on all your repositories at once. Its `return` value is None.

performs a **pull** request on all your repositories at once. Its `return` value is None. ::
`pygit.push_all()`

pygit.push_all()
performs a `push` action on all your repositories at once. Its `return` value is None.


performs a **push** action on all your repositories at once. Its `return` value is None. ::

pygit.load_all()
`pygit.load_all()`

returns a `generator` of `Commands` object for every repository.

## To do

Add **git-bash.exe**

Implement Commands.branch()

Write tests

Run test after importation to make sure every other thing works fine.

Define an update function that updates the repo dictionaries for the case when a new repo is added but the overall directory structure remains unchanged.

Git search pathsep

git check locations

C:\Program Files\Git\cmd\git.exe
C:\Program Files (x86)\Git\cmd\git.exe
C:\Program Files\Git\cmd\git.exe
C:\Users\Chidimma\AppData\Local\Programs\Git\cmd\git.exe

https://stackoverflow.com/questions/19687394/python-script-to-determine-if-a-directory-is-a-git-repository

http://gitpython.readthedocs.io/en/stable/

https://simpleisbetterthancomplex.com/tips/2017/08/11/django-tip-21-redirects-app.html
1. Refactor `initialize()` function
1. Add `git-bash.exe`
1. Implement `Commands.branch()`
1. Refactor tests
1. Auto-run test after importation to make sure every other thing works fine.
1. Define an update function that updates the repo dictionaries for the case when a new repo is added but the overall directory structure remains unchanged.

https://simpleisbetterthancomplex.com/tutorial/2017/08/20/how-to-use-celery-with-django.html
## Update git check locations

https://realpython.com/asynchronous-tasks-with-django-and-celery/
1. C:\Program Files\Git\cmd\git.exe
1. C:\Program Files (x86)\Git\cmd\git.exe
1. C:\Program Files\Git\cmd\git.exe
1. C:\Users\Chidimma\AppData\Local\Programs\Git\cmd\git.exe

0 comments on commit e395e08

Please sign in to comment.