Skip to content

Commit 1b0c60b

Browse files
committed
Initial commit
1 parent 035ad6c commit 1b0c60b

6 files changed

Lines changed: 595 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
urbackup_server_web_api_wrapper.egg-info/*
2+
dist/urbackup-server-web-api-wrapper-*.zip
3+
urbackup_api/__pycache__/*

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
1-
# urbackup-server-python-web-api-wrapper
2-
Python wrapper to access and controll an UrBackup server
1+
# urbackup-server-web-api-wrapper
2+
Python wrapper to access and control an UrBackup server
3+
4+
## Installation
5+
6+
Install with:
7+
8+
pip3 install urbackup-server-web-api-wrapper
9+
10+
## Usage
11+
12+
Start a full file backup:
13+
14+
```python
15+
import urbackup_api
16+
17+
server = urbackup_api.urbackup_server("http://127.0.0.1:55414/x", "admin", "foo")
18+
19+
server.start_full_file_backup("testclient0")
20+
```
21+
22+
List clients with no file backup in the last three days:
23+
24+
```python
25+
import urbackup_api
26+
server = urbackup_api.urbackup_server("http://127.0.0.1:55414/x", "admin", "foo")
27+
clients = server.get_status()
28+
diff_time = 3*24*60*60 # 3 days
29+
for client in clients:
30+
if client["lastbackup"]=="-" or client["lastbackup"] < time.time() - diff_time:
31+
32+
if client["lastbackup"]=="-" or client["lastbackup"]==0:
33+
lastbackup = "Never"
34+
else:
35+
lastbackup = datetime.datetime.fromtimestamp(client["lastbackup"]).strftime("%x %X")
36+
37+
print("Last file backup at {lastbackup} of client {clientname} is older than three days".format(
38+
lastbackup=lastbackup, clientname=client["name"] ) )
39+
```
40+

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.md

setup.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Always prefer setuptools over distutils
2+
from setuptools import setup, find_packages
3+
# To use a consistent encoding
4+
from codecs import open
5+
from os import path
6+
7+
here = path.abspath(path.dirname(__file__))
8+
9+
# Get the long description from the README file
10+
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
11+
long_description = f.read()
12+
13+
setup(
14+
name='urbackup-server-web-api-wrapper',
15+
16+
# Versions should comply with PEP440. For a discussion on single-sourcing
17+
# the version across setup.py and the project code, see
18+
# https://packaging.python.org/en/latest/single_source_version.html
19+
version='0.1',
20+
21+
description='Python wrapper to access and control an UrBackup server',
22+
long_description=long_description,
23+
24+
# The project's main homepage.
25+
url='https://github.com/uroni/urbackup-server-python-web-api-wrapper',
26+
27+
# Author details
28+
author='Martin Raiber',
29+
author_email='martin@urbackup.org',
30+
31+
# Choose your license
32+
license='Apache License 2.0',
33+
34+
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
35+
classifiers=[
36+
# How mature is this project? Common values are
37+
# 3 - Alpha
38+
# 4 - Beta
39+
# 5 - Production/Stable
40+
'Development Status :: 3 - Alpha',
41+
42+
# Indicate who your project is intended for
43+
'Intended Audience :: Developers',
44+
45+
# Pick your license as you wish (should match "license" above)
46+
'License :: OSI Approved :: Apache Software License',
47+
48+
# Specify the Python versions you support here. In particular, ensure
49+
# that you indicate whether you support Python 2, Python 3 or both.
50+
'Programming Language :: Python :: 3.4',
51+
'Programming Language :: Python :: 3.5',
52+
],
53+
54+
# What does your project relate to?
55+
keywords='urbackup web api client',
56+
57+
# You can just specify the packages manually here if your project is
58+
# simple. Or you can use find_packages().
59+
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
60+
61+
# Alternatively, if you want to distribute just a my_module.py, uncomment
62+
# this:
63+
# py_modules=["my_module"],
64+
65+
# List run-time dependencies here. These will be installed by pip when
66+
# your project is installed. For an analysis of "install_requires" vs pip's
67+
# requirements files see:
68+
# https://packaging.python.org/en/latest/requirements.html
69+
install_requires=[],
70+
71+
# List additional groups of dependencies here (e.g. development
72+
# dependencies). You can install these using the following syntax,
73+
# for example:
74+
# $ pip install -e .[dev,test]
75+
extras_require={
76+
'dev': [],
77+
'test': [],
78+
}
79+
)

test/urbackup_api_test.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import urbackup_api
2+
import datetime
3+
import time
4+
5+
6+
server = urbackup_api.urbackup_server("http://127.0.0.1:55414/x", "admin", "foo")
7+
8+
for extra_client in server.get_extra_clients():
9+
server.remove_extra_client(extra_client["id"])
10+
11+
computernames = """2.2.2.2
12+
3.3.3.3"""
13+
14+
for line in computernames:
15+
server.add_extra_client(line)
16+
17+
18+
clients = server.get_status()
19+
20+
# Uncomment to format time differently
21+
# locale.setlocale(locale.LC_TIME, "german")
22+
23+
diff_time = 3*24*60*60 # 3 days
24+
for client in clients:
25+
26+
if client["lastbackup"]=="-" or client["lastbackup"] < time.time() - diff_time:
27+
28+
if client["lastbackup"]=="-" or client["lastbackup"]==0:
29+
lastbackup = "Never"
30+
else:
31+
lastbackup = datetime.datetime.fromtimestamp(client["lastbackup"]).strftime("%x %X")
32+
33+
print("Last file backup at {lastbackup} of client {clientname} is older than three days".format(
34+
lastbackup=lastbackup, clientname=client["name"] ) )
35+
36+
37+
#if server.start_incr_file_backup("Johnwin7test-PC2"):
38+
# print("Started file backup successfully")
39+
#else:
40+
# print("Failed to start file backup")
41+
42+
43+
settings = server.get_client_settings("Johnwin7test-PC2")
44+
45+
for key in settings:
46+
print("{key}={value}".format(key=key, value=settings[key]))
47+
48+
print("Authkey: "+server.get_client_authkey("Johnwin7test-PC2"))
49+
50+
if server.change_client_setting("Johnwin7test-PC2", "max_image_incr", "40"):
51+
print("Changed setting successfully")
52+
else:
53+
print("Failed to change setting")
54+
55+
56+
settings = server.get_global_settings()
57+
58+
for key in settings:
59+
print("Global: {key}={value}".format(key=key, value=settings[key]))
60+
61+
62+
if server.set_global_setting("max_image_incr", "40"):
63+
print("Changed global setting successfully")
64+
else:
65+
print("Failed to change global setting")

0 commit comments

Comments
 (0)