Project

General

Profile

RE: Missing recordings after 4.0.x to 4.1/4.2 upgrade (no... ยป dvr_migrate.py

Kari Tiirikainen, 2017-06-11 08:48

 
1
#!/usr/bin/env python
2
#
3
# Migration version 4 dvr log files to version 4.2
4
#
5
# Files that need updating:
6
#   dvr/log/*       : files-list needs to be added
7
# 
8

    
9
#
10
# Imports
11
#
12

    
13
import os, sys, re, json, glob
14
import pprint
15
from optparse import OptionParser
16

    
17
#
18
# DVR
19
#
20

    
21
def update_dvr ( path ):
22

    
23
  # Update all DVR log entries
24
  for f in glob.glob(os.path.join(path, 'dvr', 'log', '*')):
25

    
26
    # Load
27
    s = open(f).read()
28
    d = json.loads(s)
29

    
30
    # Already done, files-section present
31
    if 'files' in d: continue
32

    
33
    # Update all filenames, by adding files-list. NOTE : old filenames object is left in place (compatible with 4.0)
34
    if 'filename' in d:
35
      file = dict();
36
      file['filename'] = d['filename']
37
      d['files'] =  []
38
      d['files'].append (file)
39

    
40
    # Save
41
    open(f, 'w').write(json.dumps(d, indent=2))
42

    
43
#
44
# Main
45
#
46

    
47
optp = OptionParser()
48
(opts,args) = optp.parse_args()
49
path = args[0]
50
update_dvr(path)
51
sys.exit(0)
    (1-1/1)