Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Gepetto Utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gepetto
Gepetto Utils
Commits
9dfa308d
Commit
9dfa308d
authored
8 months ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
package newcomers in nix
parent
c25833d3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
flake.nix
+26
-15
26 additions, 15 deletions
flake.nix
newcomers/README.md
+4
-6
4 additions, 6 deletions
newcomers/README.md
newcomers/default.nix
+32
-0
32 additions, 0 deletions
newcomers/default.nix
newcomers/greet_newcomers.py
+13
-6
13 additions, 6 deletions
newcomers/greet_newcomers.py
with
75 additions
and
27 deletions
flake.nix
+
26
−
15
View file @
9dfa308d
...
...
@@ -24,24 +24,35 @@
"x86_64-darwin"
];
perSystem
=
{
config
,
pkgs
,
...
}:
{
config
,
pkgs
,
self
'
,
...
}:
{
apps
.
newcomers
=
{
type
=
"app"
;
program
=
self
'
.
packages
.
newcomers
;
};
devShells
.
default
=
pkgs
.
mkShell
{
nativeBuildInputs
=
[
config
.
treefmt
.
build
.
wrapper
];
packages
=
with
pkgs
;
[
(
python3
.
withPackages
(
p
:
with
p
;
[
beautifulsoup4
httpx
ldap3
numpy
pandas
requests
tabulate
wand
]
))
];
packages
=
[
self
'
.
packages
.
python
];
};
packages
=
{
newcomers
=
pkgs
.
python3Packages
.
callPackage
./newcomers
{
};
python
=
pkgs
.
python3
.
withPackages
(
p
:
with
p
;
[
beautifulsoup4
httpx
ldap3
numpy
pandas
requests
tabulate
wand
]
);
};
treefmt
=
{
projectRootFile
=
"flake.nix"
;
...
...
This diff is collapsed.
Click to expand it.
newcomers/README.md
+
4
−
6
View file @
9dfa308d
...
...
@@ -2,17 +2,15 @@
## Get dependencies
-
Get Python 3
-
`pip3 install ldap3`
(you might need
`sudo`
, or
*better*
`--user`
, or
*best*
a virtualenv)
-
`mkdir -p ~/.cache`
This project is packaged with a nix flake
## Go !
-
`./greet_newcomers.py`
On the first time, it will construct a database of the
guy
s already here.
On the first time, it will construct a database of the
member
s already here.
After that, on each launch, it will find the new
guy
s, and send them a greeting mail.
After that, on each launch, it will find the new
comer
s, and send them a greeting mail.
The template of this mail is in
`template.txt`
.
## Cron job
...
...
@@ -20,5 +18,5 @@ The template of this mail is in `template.txt`.
To run this script everyday at 5 AM:
```
bash
(
crontab
-l
;
echo
"0 5 * * *
$(
which python
)
$(
pwd
)
/greet_
newcomers
.py
"
)
| crontab -
(
crontab
-l
;
echo
"0 5 * * *
cd
$(
pwd
)
; nix run .#
newcomers"
)
| crontab -
```
This diff is collapsed.
Click to expand it.
newcomers/default.nix
0 → 100644
+
32
−
0
View file @
9dfa308d
{
lib
,
ldap3
,
buildPythonApplication
}:
buildPythonApplication
{
pname
=
"greet-newcomers"
;
version
=
"1.0.0"
;
pyproject
=
false
;
dependencies
=
[
ldap3
];
src
=
lib
.
fileset
.
toSource
{
root
=
./.
;
fileset
=
lib
.
fileset
.
unions
[
./greet_newcomers.py
./template.txt
];
};
installPhase
=
''
install -D -m 755 greet_newcomers.py $out/bin/greet-newcomers
install -D -m 644 template.txt $out/share/greet-newcomers/template.txt
''
;
meta
=
{
description
=
"Greet gepetto newcomers"
;
homepage
=
"https://github.com/gepetto/gepetto-utils/tree/master/newcomers"
;
license
=
lib
.
licenses
.
bsd2
;
maintainers
=
[
lib
.
maintainers
.
nim65s
];
mainProgram
=
"greet-newcomers"
;
};
}
This diff is collapsed.
Click to expand it.
newcomers/greet_newcomers.py
+
13
−
6
View file @
9dfa308d
...
...
@@ -3,13 +3,14 @@
import
shelve
from
email.mime.text
import
MIMEText
from
getpass
import
getuser
from
s
mtplib
import
SMTP
from
o
s
import
environ
from
pathlib
import
Path
from
smtplib
import
SMTP
from
ldap3
import
Connection
HERE
=
Path
(
__file__
).
resolve
().
parent
SHELF
=
str
(
HERE
/
"
.cache
"
)
SHELF
=
Path
(
environ
.
get
(
"
XDG_CACHE_HOME
"
,
Path
.
home
()
/
"
.cache
"
))
/
"
greet-newcomers
"
def
get_gepetto
():
...
...
@@ -53,7 +54,13 @@ def greet(to, sender):
if
"
@
"
not
in
to
:
to
=
"
%s@laas.fr
"
%
to
with
(
HERE
/
"
template.txt
"
).
open
()
as
f
:
template
=
HERE
/
"
template.txt
"
if
not
template
.
exists
():
template
=
HERE
.
parent
/
"
share
"
/
"
greet-newcomers
"
/
"
template.txt
"
if
not
template
.
exists
():
err
=
f
"
can
'
t find template.txt around
{
HERE
}
"
raise
RuntimeError
(
err
)
with
template
.
open
()
as
f
:
msg
=
MIMEText
(
f
.
read
())
msg
[
"
Subject
"
]
=
"
Welcome in Gepetto !
"
...
...
@@ -86,9 +93,9 @@ if __name__ == "__main__":
# Retrieve the login of the current user, who must already be a member
me
=
whoami
(
gepetto
)
for
guy
in
gepetto_ldap
:
if
guy
not
in
gepetto
:
greet
(
guy
,
me
)
for
member
in
gepetto_ldap
:
if
member
not
in
gepetto
:
greet
(
member
,
me
)
# Save the new list
with
shelve
.
open
(
SHELF
)
as
shelf
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment