Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions gitkv.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
(define-module (gitkv)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix git-download)
#:use-module (guix build-system cmake)
#:use-module (guix build-system python)
#:use-module (gnu packages curl)
#:use-module (gnu packages linux)
#:use-module (gnu packages ssh)
#:use-module (gnu packages pkg-config)
#:use-module (gnu packages python)
#:use-module (gnu packages compression)
#:use-module (gnu packages tls)
#:use-module (gnu packages)
#:use-module (gnu packages version-control))

(define-public libgit2-0.25.0
(package
(name "libgit2")
(version "0.25.0")
(source (origin
(method url-fetch)
(uri (string-append "https://github.com/libgit2/libgit2/"
"archive/v" version ".tar.gz"))
(file-name (string-append name "-" version ".tar.gz"))
(sha256
(base32
"0yl37h6hsmp8lky74agrl97rqvwni5gisrgrbbjl8rillc8n5ihh"))))
(build-system cmake-build-system)
(arguments
`(#:phases
(modify-phases %standard-phases
(add-after 'unpack 'fix-hardcoded-paths
(lambda _
(substitute* "tests/repo/init.c"
(("#!/bin/sh") (string-append "#!" (which "sh"))))
(substitute* "tests/clar/fs.h"
(("/bin/cp") (which "cp"))
(("/bin/rm") (which "rm")))
#t))
(add-after 'unpack 'apply-patch
(lambda* (#:key inputs #:allow-other-keys)
;; XXX: For some reason adding the patch in 'patches', which
;; leads to a new tarball with all timestamps reset and ordering
;; by name (slightly different file order compared to the
;; original tarball) leads to an obscure Python error while
;; running 'generate.py':
;; 'Module' object has no attribute 'callbacks'
;; Thus, apply the patch here, which minimizes disruption.
(let ((patch (assoc-ref inputs "patch")))
(zero? (system* "patch" "-p1" "--force" "--input" patch)))))
;; Run checks more verbosely.
(replace 'check
(lambda _ (zero? (system* "./libgit2_clar" "-v" "-Q")))))))
(inputs
`(("libssh2" ,libssh2)
("libcurl" ,curl)
("python" ,python-wrapper)
("patch" ,(search-patch "libgit2-use-after-free.patch"))))
(native-inputs
`(("pkg-config" ,pkg-config)))
(propagated-inputs
;; These two libraries are in 'Requires.private' in libgit2.pc.
`(("openssl" ,openssl)
("zlib" ,zlib)))
(home-page "https://libgit2.github.com/")
(synopsis "Library providing Git core methods")
(description
"Libgit2 is a portable, pure C implementation of the Git core methods
provided as a re-entrant linkable library with a solid API, allowing you to
write native speed custom Git applications in any language with bindings.")
;; GPLv2 with linking exception
(license license:gpl2)))


(define-public python-gitkv
(package
(name "python-gitkv")
(version "0.0.5")
(source (origin
(method url-fetch)
(uri (string-append "https://github.com/edouardklein/gitkv/archive/v"
version ".tar.gz"))
(file-name (string-append name "-" version ".tar.gz"))
(sha256
(base32
"use guix download to find the hash"))))
(build-system python-build-system)
(arguments
`(#:phases
(modify-phases %standard-phases
(delete 'check)
(add-after 'install 'test
(lambda _ (zero? (system* "make" "test")))))))
(inputs
`(("python-coverage" ,python-coverage)
("python-flake8" ,python-flake8)
("python-sphinx" ,python-sphinx)))
(propagated-inputs
`(("libgit2-0.25.0" ,libgit2-0.25.0)
("python-cffi" ,python-cffi)
("python-pygit2" ,python-pygit2)
("git" ,git)
("python" ,python)))

(home-page "https://github.com/edouardklein/gitkv")
(synopsis "Use a git repo as a key-value store.")
(description
"Use a git repo as a key-value store.")
;; GPLv2 with linking exception
(license license:agpl3)))

(define-public python-gitgv-dev
(let ((commit "16096072ec5eefcfe04da5c74cd9989ef2852918")
(revision "1"))
(package
(name "python-gitkv-dev")
(version (string-append "0.0.4-" revision "."
(string-take commit 7)))
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/edouardklein/gitkv.git")
(commit commit)))
(file-name (string-append name "-" version "-checkout"))
(sha256
(base32
"05zjqnkc0vgqxvsg8m1v041l0s5mnm1phbghr3wjcl19bkdwfhih"))))
(build-system python-build-system)
(arguments
`(#:phases
(modify-phases %standard-phases
(delete 'check)
(add-after 'install 'test
(lambda _ (zero? (system* "make" "test")))))))
(inputs
`(("python-coverage" ,python-coverage)
("python-flake8" ,python-flake8)
("python-sphinx" ,python-sphinx)))
(propagated-inputs
`(("libgit2-0.25.0" ,libgit2-0.25.0)
("python-cffi" ,python-cffi)
("python-pygit2" ,python-pygit2)
("git" ,git)
("python" ,python)))

(home-page "https://github.com/edouardklein/gitkv")
(synopsis "Use a git repo as a key-value store.")
(description
"Use a git repo as a key-value store.")
;; GPLv2 with linking exception
(license license:agpl3))))
27 changes: 5 additions & 22 deletions gitkv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@
import pygit2
import subprocess
import tempfile
import datetime
import time
import importlib
import os
import re

logger = logging.getLogger('gitkv')
logger.setLevel(level=logging.INFO)
__version__ = '0.0.4'
__version__ = '0.0.5'


def run_cmd(cmd, **kwargs):
Expand All @@ -85,22 +84,6 @@ def run_cmd(cmd, **kwargs):
raise RuntimeError


def utc_to_timestamp(str_utc):
"""Convert a date from UTC to UNIX timestamp

:param str_utc: UTC date (i.e : "2017-05-30 09:00:00")
:return: int UNIX timestamp (i.e. : 1496127600)

>>> import gitkv
>>> # 09:00:00 AM, Date 30 May 2017
>>> gitkv.utc_to_timestamp("2017-05-30 09:00:00") == 1496127600
True
"""
return time.mktime(
datetime.datetime.strptime(
str_utc,
'%Y-%m-%d %H:%M:%S').timetuple())


class open:
"""Open a file in a repository.
Expand Down Expand Up @@ -274,19 +257,19 @@ def git_clone(self, url, path):

def git_push(self):
"""Push to remote repository."""
run_cmd(['git', 'push', 'origin', self.branch], cwd=self.path)
run_cmd(['git', '-c', 'user.email="[email protected]"', '-c', 'user.name="gitkv"', 'push', 'origin', self.branch], cwd=self.path)

def git_pull(self):
"""Pull from remote repository."""
run_cmd(['git', 'pull', 'origin', self.branch], cwd=self.path)
run_cmd(['git', '-c', 'user.email="[email protected]"', '-c', 'user.name="gitkv"', 'pull', 'origin', self.branch], cwd=self.path)

def git_commit(self, message=None):
"""Create a commit."""
if message is None:
message = self.commit_message
run_cmd(['git', 'add', '.'], cwd=self.path)
try:
run_cmd(['git', 'commit', '-m', message], cwd=self.path)
run_cmd(['git', '-c', 'user.email="[email protected]"', '-c', 'user.name="gitkv"', 'commit', '-m', message], cwd=self.path)
except:
pass

Expand Down Expand Up @@ -547,7 +530,7 @@ def git_commit(self, message=None):
# git commit
try:
output = subprocess.check_output(
['git', 'commit', '-m', message],
['git', '-c', 'user.email="[email protected]"', '-c', 'user.name="gitkv"', 'commit', '-m', message],
cwd=self.gkvrepo.path)
logger.debug('{}\n\t{}'.format('git commit:\n\t',
output))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from codecs import open
from os import path

__version__ = '0.0.4'
__version__ = '0.0.5'

here = path.abspath(path.dirname(__file__))

Expand Down