1818 OperationTypeError ,
1919)
2020from 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+ )
2130
2231from .util .compat import fspath
2332from .util .files import ensure_mode_int
@@ -57,7 +66,7 @@ def download(
5766 )
5867 '''
5968
60- info = host .fact . windows_file ( dest )
69+ info = host .get_fact ( WindowsFile , name = dest )
6170 # Destination is a directory?
6271 if info is False :
6372 raise OperationError (
@@ -76,21 +85,23 @@ def download(
7685 else :
7786 if cache_time :
7887 # 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+ )
8192 if info ['mtime' ] and info ['mtime' ] > cache_time :
8293 download = True
8394
8495 if sha1sum :
85- if sha1sum != host .fact . windows_sha1_file ( dest ):
96+ if sha1sum != host .get_fact ( WindowsSha1File , name = dest ):
8697 download = True
8798
8899 if sha256sum :
89- if sha256sum != host .fact . windows_sha256_file ( dest ):
100+ if sha256sum != host .get_fact ( WindowsSha256File , name = dest ):
90101 download = True
91102
92103 if md5sum :
93- if md5sum != host .fact . windows_md5_file ( dest ):
104+ if md5sum != host .get_fact ( WindowsMd5File , name = dest ):
94105 download = True
95106
96107 # If we download, always do user/group/mode as SSH user may be different
@@ -191,7 +202,7 @@ def put(
191202 raise IOError ('No such file: {0}' .format (local_file ))
192203
193204 mode = ensure_mode_int (mode )
194- remote_file = host .fact . windows_file ( dest )
205+ remote_file = host .get_fact ( WindowsFile , name = dest )
195206
196207 if create_remote_dir :
197208 yield _create_remote_dir (state , host , dest , user , group )
@@ -209,7 +220,7 @@ def put(
209220 # File exists, check sum and check user/group/mode if supplied
210221 else :
211222 local_sum = get_file_sha1 (src )
212- remote_sum = host .fact . windows_sha1_file ( dest )
223+ remote_sum = host .get_fact ( WindowsSha1File , name = dest )
213224
214225 # Check sha1sum, upload if needed
215226 if local_sum != remote_sum :
@@ -283,7 +294,7 @@ def file(
283294 raise OperationTypeError ('Name must be a string' )
284295
285296 # mode = ensure_mode_int(mode)
286- info = host .fact . windows_file ( path )
297+ info = host .get_fact ( WindowsFile , name = path )
287298
288299 # Not a file?!
289300 if info is False :
@@ -395,7 +406,7 @@ def directory(
395406 if not isinstance (path , six .string_types ):
396407 raise OperationTypeError ('Name must be a string' )
397408
398- info = host .fact . windows_directory ( path )
409+ info = host .get_fact ( WindowsDirectory , name = path )
399410
400411 # Not a directory?!
401412 if info is False :
@@ -410,9 +421,9 @@ def directory(
410421# yield chown(path, user, group, recursive=recursive)
411422#
412423 # 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 } ,
416427 data = {'type' : 'directory' },
417428 )
418429
@@ -504,7 +515,7 @@ def link(
504515 if present and not target :
505516 raise OperationError ('If present is True target must be provided' )
506517
507- info = host .fact . windows_link ( path )
518+ info = host .get_fact ( WindowsLink , name = path )
508519
509520 # Not a link?
510521 if info is not None and not info :
@@ -531,16 +542,16 @@ def link(
531542 # if user or group:
532543 # yield chown(path, user, group, dereference=False)
533544
534- # host.fact._create (
535- # 'windows_link' ,
536- # args=( path,) ,
545+ # host.create_fact (
546+ # WindowsLink ,
547+ # kwargs={'name': path} ,
537548 # data={'link_target': target, 'group': group, 'user': user},
538549 # )
539550
540551 # It exists and we don't want it
541552 elif (assume_present or info ) and not present :
542553 yield remove_cmd
543- # host.fact._delete('windows_link', args=( path,) )
554+ # host.delete_fact(WindowsLink, kwargs={'name': path} )
544555
545556 else :
546557 host .noop ('link {0} already exists and force=False' .format (path ))
0 commit comments