Skip to content

Commit

Permalink
Apply pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iranzo committed May 17, 2021
1 parent 731d902 commit 7513998
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 79 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401, E402, E722, C901
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Bug report
about: Create a report to help us improve

---

**What does happen/fail?**
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Feature request
about: Suggest an idea for this project

---

**What are you missing in citmetrics?**
Expand Down
4 changes: 0 additions & 4 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
### Actual behavior


### Expected behavior


### Steps to reproduce the behavior


58 changes: 58 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
fail_fast: true
repos:
- repo: meta
hooks:
- id: check-useless-excludes
- repo: https://github.com/prettier/prettier
rev: 2.0.5
hooks:
- id: prettier
files: \.(css|js|md|markdown|json)
- repo: https://github.com/python/black
rev: 19.10b0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
args: [--unsafe]
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: forbid-new-submodules
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
- repo: local
hooks:
- id: shfmt
name: shfmt
minimum_pre_commit_version: 2.4.0
language: golang
additional_dependencies:
- mvdan.cc/sh/v3/cmd/[email protected]
entry: shfmt
args:
- -w
- -i
- '0'
types:
- shell

- repo: https://github.com/asottile/blacken-docs
rev: v1.7.0
hooks:
- id: blacken-docs
20 changes: 10 additions & 10 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ In the interest of fostering an open and welcoming environment, we as contributo

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Expand Down
34 changes: 17 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ open an [issue](https://github.com/risuorg/risumetrics/issues/new).

# How to contribute code

We encourage you to contribute new plugins. We use [gerrithub][] for
reviewing proposed changes. The submission process looking something
We encourage you to contribute new plugins. We use [gerrithub][] for
reviewing proposed changes. The submission process looking something
like this:

[gerrithub]: https://gerrithub.io/

1. Clone the risumetrics repository:
1. Clone the risumetrics repository:

git clone https://github.com/risuorg/risumetrics

2. Configure the `git-review` tool:
2. Configure the `git-review` tool:

git-review -s

3. Check out a branch in which to make your changes:
3. Check out a branch in which to make your changes:

git checkout -b "your-new-branch"

4. Edit your files and validate with tox:
4. Edit your files and validate with tox:

tox # this will check the changes for some errors

1. NOTE: tox will run python 2.7, pep8 and python 3.5 tests, if your environment lacks for example python 3.5, do execute tox -l to see the available tests and skip that one, for example:

~~~sh
tox -e pep8
tox -e py27
# We're skipping tox -e py35 which is also invoked by default when tox is executed without arguments.
~~~
```sh
tox -e pep8
tox -e py27
# We're skipping tox -e py35 which is also invoked by default when tox is executed without arguments.
```

5. Update your local repository:
5. Update your local repository:

git add $modified_files
git commit
Expand All @@ -44,23 +44,23 @@ like this:

If the commit fixes a github open issue, also use `Closes #$ISSUEID` so github automatically closes it once merged referencing the commit.

6. Submit your changes for review:
6. Submit your changes for review:

git-review

Then wait for your changes to be reviewed. It is common for reviewers
Then wait for your changes to be reviewed. It is common for reviewers
to request changes; when this happens:

1. Edit your files and revalidate with tox:
1. Edit your files and revalidate with tox:

tox # this will check the new changes for some errors

2. Update your existing commit. Do not create a new commit!
2. Update your existing commit. Do not create a new commit!

git add $modified_files
git commit --amend

3. Resubmit the change:
3. Resubmit the change:

git-review

Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@
[![Coverage Status](https://coveralls.io/repos/github/risuorg/citmetrics/badge.svg?branch=master)](https://coveralls.io/github/risuorg/citmetrics?branch=master)
[![Release status](https://img.shields.io/github/release/risuorg/citmetrics.svg)](https://github.com/risuorg/citmetrics/releases)


<img src="doc/citmetrics.png" width="20%" border=0 align="right">


### Introduction

Citmetrics is a set of simple scripts to receive incoming `--call-home <serveruri>` over http and store as json files on disk.
Citmetrics is a set of simple scripts to receive incoming `--call-home <serveruri>` over http and store as json files on disk.

Those files will be later analyzed for metrics information like most 'hit' issue on executions to detect plugins that always return the same status and hence are not useful or erroneous or even to detect old plugins that are no longer relevant in current systems.

### Execution of receiving server

In an environment with tox run:

~~~sh
```sh
tox -e start
~~~
```

It will start webserver with default port of `80` so ensure having proper privileges for doing so.
It will start webserver with default port of `80` so ensure having proper privileges for doing so.

This will start the 'webserver' that will receive the jsons generated by [risu](https://github.com/risuorg/risu) and store them:

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Introduction

Citmetrics is a set of simple scripts to receive incoming `--call-home <serveruri>` over http and store as json files on disk.

Those files will be later analized for metrics information like most 'hit' issue on executions to detect plugins that always return the same status and hence are not useful or erroneous or even to detect old plugins that are no longer relevant in current systems.
Those files will be later analized for metrics information like most 'hit' issue on executions to detect plugins that always return the same status and hence are not useful or erroneous or even to detect old plugins that are no longer relevant in current systems.
2 changes: 1 addition & 1 deletion citmetrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
# encoding: utf-8
# -*- coding: utf-8 -*-
# Copyright (C) 2017, 2018 Pablo Iranzo Gómez <[email protected]>
16 changes: 11 additions & 5 deletions citmetrics/convert-txt-to-json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# encoding: utf-8
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Pablo Iranzo Gómez <[email protected]>

import json
Expand All @@ -8,26 +8,32 @@

def main():
files = []
folders = [os.getcwd()] # Walk the folders and subfolders for files based on our criteria
folders = [
os.getcwd()
] # Walk the folders and subfolders for files based on our criteria
for folder in folders:
for items in os.walk(folder, followlinks=True):
root = items[0]
filenames = items[2]

for filename in filenames:
filepath = os.path.join(root, filename)
if os.path.splitext(filepath)[1] == '.txt' and '.json' in filename and 'risu' in filename:
if (
os.path.splitext(filepath)[1] == ".txt"
and ".json" in filename
and "risu" in filename
):
files.append(filepath)

for filename in files:
contents = open(filename, 'r').read()
contents = open(filename, "r").read()
newcontents = "\n".join(contents.split("\n")[3:-2])

# Remove the .txt ending
newfilename = "%s" % os.path.splitext(filename)[0]

try:
with open(newfilename, 'w') as fd:
with open(newfilename, "w") as fd:
json.dump(json.loads(newcontents), fd, indent=2)
print("Converted successfully: %s" % newfilename)
os.remove(filename)
Expand Down
10 changes: 6 additions & 4 deletions citmetrics/validatejsons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# encoding: utf-8
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Pablo Iranzo Gómez <[email protected]>
#
# Description: validate jsons as valid for risu or remove in case of corruption
Expand All @@ -10,21 +10,23 @@

def main():
files = []
folders = [os.getcwd()] # Walk the folders and subfolders for files based on our criteria
folders = [
os.getcwd()
] # Walk the folders and subfolders for files based on our criteria
for folder in folders:
for items in os.walk(folder, followlinks=True):
root = items[0]
filenames = items[2]

for filename in filenames:
filepath = os.path.join(root, filename)
if os.path.splitext(filepath)[1] == '.json' and 'risu' in filename:
if os.path.splitext(filepath)[1] == ".json" and "risu" in filename:
files.append(filepath)

for filename in files:
print("Processing file: %s" % filename)
try:
json.load(open(filename, 'r'))
json.load(open(filename, "r"))
except:
print("Processing failed, removing file")
os.remove(filename)
Expand Down
23 changes: 13 additions & 10 deletions citmetrics/web.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# encoding: utf-8
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Pablo Iranzo Gómez <[email protected]>

import datetime
Expand All @@ -16,7 +16,7 @@ def _set_headers(self):
:return:
"""
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.send_header("Content-type", "text/html")
self.end_headers()

def do_GET(self):
Expand All @@ -36,26 +36,29 @@ def do_POST(self):
"""
Processes POST requests
"""
content_length = int(self.headers['Content-Length']) # <--- data size
content_length = int(self.headers["Content-Length"]) # <--- data size
post_data = self.rfile.read(content_length) # <--- Gets the data itself
contents = post_data.decode('utf-8')
filename = "risu-%s-%s.json" % (datetime.datetime.now().strftime("%Y%m%d-%H%M%S"), random.random())
contents = post_data.decode("utf-8")
filename = "risu-%s-%s.json" % (
datetime.datetime.now().strftime("%Y%m%d-%H%M%S"),
random.random(),
)
print("Incoming file: %s" % filename)

try:
with open(filename, 'w') as fd:
with open(filename, "w") as fd:
json.dump(json.loads(contents), fd, indent=2)
except:
try:
with open(filename, 'w') as fd:
with open(filename, "w") as fd:
newdata = json.loads("\n".join(contents.split("\n")[3:-2]))
json.dump(newdata, fd, indent=2)
print("Old format of json detected and converted")

except:
# Corner case if we're getting something else we don't know about
os.remove(filename)
with open("%s.txt" % filename, 'w') as fd:
with open("%s.txt" % filename, "w") as fd:
fd.write(contents)
print("Invalid format received")

Expand All @@ -70,9 +73,9 @@ def run(server_class=HTTPServer, handler_class=S, port=80):
:param handler_class:
:param port:
"""
server_address = ('', port)
server_address = ("", port)
httpd = server_class(server_address, handler_class)
print('Starting httpd...')
print("Starting httpd...")
httpd.serve_forever()


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests
requests
Loading

0 comments on commit 7513998

Please sign in to comment.