18
18
OperationTypeError ,
19
19
)
20
20
from pyinfra .api .util import get_file_sha1
21
+ from pyinfra .facts .windows import WindowsDate
22
+ from pyinfra .facts .windows_files import (
23
+ WindowsDirectory ,
24
+ WindowsFile ,
25
+ WindowsLink ,
26
+ WindowsMd5File ,
27
+ WindowsSha1File ,
28
+ WindowsSha256File ,
29
+ )
21
30
22
31
from .util .compat import fspath
23
32
from .util .files import ensure_mode_int
@@ -57,7 +66,7 @@ def download(
57
66
)
58
67
'''
59
68
60
- info = host .fact . windows_file ( dest )
69
+ info = host .get_fact ( WindowsFile , name = dest )
61
70
# Destination is a directory?
62
71
if info is False :
63
72
raise OperationError (
@@ -76,21 +85,23 @@ def download(
76
85
else :
77
86
if cache_time :
78
87
# Time on files is not tz-aware, and will be the same tz as the server's time,
79
- # so we can safely remove the tzinfo from host.fact.date before comparison.
80
- cache_time = host .fact .windows_date .replace (tzinfo = None ) - timedelta (seconds = cache_time )
88
+ # so we can safely remove the tzinfo from WindowsDate before comparison.
89
+ cache_time = (
90
+ host .get_fact (WindowsDate ).replace (tzinfo = None ) - timedelta (seconds = cache_time )
91
+ )
81
92
if info ['mtime' ] and info ['mtime' ] > cache_time :
82
93
download = True
83
94
84
95
if sha1sum :
85
- if sha1sum != host .fact . windows_sha1_file ( dest ):
96
+ if sha1sum != host .get_fact ( WindowsSha1File , name = dest ):
86
97
download = True
87
98
88
99
if sha256sum :
89
- if sha256sum != host .fact . windows_sha256_file ( dest ):
100
+ if sha256sum != host .get_fact ( WindowsSha256File , name = dest ):
90
101
download = True
91
102
92
103
if md5sum :
93
- if md5sum != host .fact . windows_md5_file ( dest ):
104
+ if md5sum != host .get_fact ( WindowsMd5File , name = dest ):
94
105
download = True
95
106
96
107
# If we download, always do user/group/mode as SSH user may be different
@@ -191,7 +202,7 @@ def put(
191
202
raise IOError ('No such file: {0}' .format (local_file ))
192
203
193
204
mode = ensure_mode_int (mode )
194
- remote_file = host .fact . windows_file ( dest )
205
+ remote_file = host .get_fact ( WindowsFile , name = dest )
195
206
196
207
if create_remote_dir :
197
208
yield _create_remote_dir (state , host , dest , user , group )
@@ -209,7 +220,7 @@ def put(
209
220
# File exists, check sum and check user/group/mode if supplied
210
221
else :
211
222
local_sum = get_file_sha1 (src )
212
- remote_sum = host .fact . windows_sha1_file ( dest )
223
+ remote_sum = host .get_fact ( WindowsSha1File , name = dest )
213
224
214
225
# Check sha1sum, upload if needed
215
226
if local_sum != remote_sum :
@@ -283,7 +294,7 @@ def file(
283
294
raise OperationTypeError ('Name must be a string' )
284
295
285
296
# mode = ensure_mode_int(mode)
286
- info = host .fact . windows_file ( path )
297
+ info = host .get_fact ( WindowsFile , name = path )
287
298
288
299
# Not a file?!
289
300
if info is False :
@@ -395,7 +406,7 @@ def directory(
395
406
if not isinstance (path , six .string_types ):
396
407
raise OperationTypeError ('Name must be a string' )
397
408
398
- info = host .fact . windows_directory ( path )
409
+ info = host .get_fact ( WindowsDirectory , name = path )
399
410
400
411
# Not a directory?!
401
412
if info is False :
@@ -410,9 +421,9 @@ def directory(
410
421
# yield chown(path, user, group, recursive=recursive)
411
422
#
412
423
# Somewhat bare fact, should flesh out more
413
- host .fact . _create (
414
- 'windows_directory' ,
415
- args = ( path ,) ,
424
+ host .create_fact (
425
+ WindowsDate ,
426
+ kwargs = { 'name' : path } ,
416
427
data = {'type' : 'directory' },
417
428
)
418
429
@@ -504,7 +515,7 @@ def link(
504
515
if present and not target :
505
516
raise OperationError ('If present is True target must be provided' )
506
517
507
- info = host .fact . windows_link ( path )
518
+ info = host .get_fact ( WindowsLink , name = path )
508
519
509
520
# Not a link?
510
521
if info is not None and not info :
@@ -531,16 +542,16 @@ def link(
531
542
# if user or group:
532
543
# yield chown(path, user, group, dereference=False)
533
544
534
- # host.fact._create (
535
- # 'windows_link' ,
536
- # args=( path,) ,
545
+ # host.create_fact (
546
+ # WindowsLink ,
547
+ # kwargs={'name': path} ,
537
548
# data={'link_target': target, 'group': group, 'user': user},
538
549
# )
539
550
540
551
# It exists and we don't want it
541
552
elif (assume_present or info ) and not present :
542
553
yield remove_cmd
543
- # host.fact._delete('windows_link', args=( path,) )
554
+ # host.delete_fact(WindowsLink, kwargs={'name': path} )
544
555
545
556
else :
546
557
host .noop ('link {0} already exists and force=False' .format (path ))
0 commit comments