aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2015-07-19 03:42:12 +0200
committerVG <vg@devys.org>2015-07-19 03:42:12 +0200
commit6f1ef76174f7cc5de369b45c203a5e5001cdf1c3 (patch)
tree8031b808421e1a9931029a9da5304e49ccd82ff1
parent49a2da7bf5253a5c3769a783ce182e83cadf1c4a (diff)
downloaduuidxer-6f1ef76174f7cc5de369b45c203a5e5001cdf1c3.tar.gz
uuidxer-6f1ef76174f7cc5de369b45c203a5e5001cdf1c3.tar.bz2
uuidxer-6f1ef76174f7cc5de369b45c203a5e5001cdf1c3.zip
finish first implementation of scan.py
-rw-r--r--__init__.py0
-rw-r--r--readme.rst4
-rwxr-xr-x[-rw-r--r--]scan.py50
-rw-r--r--uuid-rules.rst2
4 files changed, 52 insertions, 4 deletions
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/__init__.py
diff --git a/readme.rst b/readme.rst
index caed21a..f6037eb 100644
--- a/readme.rst
+++ b/readme.rst
@@ -1 +1,5 @@
Beta
+
+Resources:
+
+https://nylas.com/blog/packaging-deploying-python
diff --git a/scan.py b/scan.py
index c611920..7432cef 100644..100755
--- a/scan.py
+++ b/scan.py
@@ -1,10 +1,54 @@
#!/usr/bin/python3
+import os
import uuid
-import Path from pathlib
+import time
+import pickle
+
START_DIR = "/storage/animes"
+DB_FILENAME = "/storage/animes.db"
+uuid_msg = '''{uuid}
+creation_date: {date}
+orig_hostname: {hostname}
+'''
+
+
+def create_uuid_txt(root, hostname=os.uname().nodename):
+ my_uuid = str(uuid.uuid4())
+ with open(os.path.join(root, 'uuid.txt'), 'w') as out:
+ out.write(uuid_msg.format(uuid=my_uuid,
+ date=time.strftime('%F %T'),
+ hostname=hostname))
+ return my_uuid
+
+
+def partition(pred, iterable):
+ 'Use a predicate to partition entries into false and true entries'
+ result = [], []
+ for x in iterable:
+ result[pred(x)].append(x)
+ return result
+
+
+def main():
+ db = []
+ with open(DB_FILENAME + '.new', 'wb') as out:
+ for root, dirs, files in os.walk(START_DIR):
+ files, uuids = partition(lambda f: '/uuid.txt' in f,
+ (os.path.join(root, f) for f in files))
+ if len(uuids) == 1:
+ my_uuid = open(uuids[0]).readline().strip()
+ else:
+ print('removing:', uuids)
+ for f in uuids:
+ os.unlink(f)
+ my_uuid = create_uuid_txt(root)
+ db.append((my_uuid, [(f, os.stat(f).st_size) for f in files]))
+
+ pickle.dump(db, out)
+ os.rename(DB_FILENAME + '.new', DB_FILENAME)
-for root, dirs, files in os.walk(START_DIR):
- s
+if __name__ == '__main__':
+ main()
diff --git a/uuid-rules.rst b/uuid-rules.rst
index 8c7b1e2..7ec3ad8 100644
--- a/uuid-rules.rst
+++ b/uuid-rules.rst
@@ -7,7 +7,7 @@ Lors d'un réorganisation, il faut:
l'arborescence.
-On réserve uuid.txt*.
+On réserve `uuid.txt*`.
scan: